git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH for-maint] apply: gitdiff_verify_name(): accept "/dev/null\r"

From
LELaszlo Ersek <lersek@redhat.com>
Date
Sep 23, 2014, 01:09 UTC
Message-ID
<1411434583-27692-1-git-send-email-lersek@redhat.com>

The edk2 (EFI Development Kit II) project at <https://github.com/tianocore/edk2/> uses CRLF line endings.

The following small reproducer demonstrates how gitdiff_verify_name() breaks when it meets the usual git patches workflow in combination with CRLF line endings:

1. Prepare the test repo:
  mkdir testdir
  cd testdir
  git init
  git config core.whitespace cr-at-eol
  git config am.keepcr true
  touch f1
  git add f1
  git commit -m 'initial import'
2. In the contributor role, write a patch that creates a new file
(adhering to the CRLF convention), submit it, then clean up:
  git checkout -b branch1 master
  echo 'hello world' | unix2dos >f2
  git add f2
  git commit -m 'add f2'
  git format-patch master..branch1
  git send-email 0001-add-f2.patch
  # send it to yourself -- make sure it goes through your MTA
  git clean -fdx
3. In the reviewer / tester / maintainer role, save the patch from your
email client to a local file. Assume that your email client does not
corrupt the patch when saving it. (Thunderbird doesn't corrupt it, for
example.) Once saved, try to apply the patch email to a new branch.
  git checkout -b branch2 master
  git am /path/to/the/saved/file
  -> Applying: add f2
  -> fatal: git apply: bad git-diff - expected /dev/null on line 9

This happens because am.keepcr==true keeps the CRLFs intact (as it should in fact), but then "/dev/null\r" in the diff header trips up gitdiff_verify_name().

Fix it by reusing the is_dev_null() helper function, which in effect changes the condition from

  memcmp("/dev/null", line, 9) || line[9] != '\n'
to
  memcmp("/dev/null", line, 9) || !isspace(line[9])
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
Notes:
    I'm not subscribed to the list; please keep me CC'd. Thanks.
 builtin/apply.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 6b7c764..a9c6a08 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -955,7 +955,7 @@ static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name,
 	}
 	else {
 		/* expect "/dev/null" */
-		if (memcmp("/dev/null", line, 9) || line[9] != '\n')
+		if (!is_dev_null(line))
 			die(_("git apply: bad git-diff - expected /dev/null on line %d"), linenr);
 		return NULL;
 	}
-- 
1.8.3.1
Next: Junio C Hamano
Message 1 of 15 in “apply: gitdiff_verify_name(): accept "/dev/null\r"”
  1. apply: gitdiff_verify_name(): accept "/dev/null\r"Laszlo Ersek, Sep 23, 2014
  2. Junio C HamanoSep 23, 2014
  3. Laszlo ErsekSep 23, 2014
  4. Junio C HamanoSep 23, 2014
  5. Laszlo ErsekSep 23, 2014
  6. Junio C HamanoSep 23, 2014
  7. Laszlo ErsekSep 23, 2014
  8. Junio C HamanoSep 23, 2014
  9. Laszlo ErsekSep 23, 2014
  10. Junio C HamanoSep 23, 2014
  11. Laszlo ErsekSep 23, 2014
  12. Junio C HamanoSep 23, 2014
  13. Laszlo ErsekSep 24, 2014
  14. Junio C HamanoSep 24, 2014
  15. Junio C HamanoSep 23, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.