git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH for-maint] apply: gitdiff_verify_name(): accept "/dev/null\r"
@ 2014-09-23  1:09 Laszlo Ersek
  2014-09-23 18:54 ` Junio C Hamano
  0 siblings, 1 reply; 15+ messages in thread
From: Laszlo Ersek @ 2014-09-23  1:09 UTC (permalink / raw)
  To: gitster, git, jordan.l.justen, matt.fleming, lersek

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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-09-24 17:55 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-23  1:09 [PATCH for-maint] apply: gitdiff_verify_name(): accept "/dev/null\r" Laszlo Ersek
2014-09-23 18:54 ` Junio C Hamano
2014-09-23 19:31   ` Laszlo Ersek
2014-09-23 19:56     ` Junio C Hamano
2014-09-23 20:33       ` Laszlo Ersek
2014-09-23 20:40         ` Junio C Hamano
2014-09-23 20:57           ` Laszlo Ersek
2014-09-23 20:02     ` Junio C Hamano
2014-09-23 20:32       ` Laszlo Ersek
2014-09-23 20:35         ` Junio C Hamano
2014-09-23 20:49           ` Laszlo Ersek
2014-09-23 21:35             ` Junio C Hamano
2014-09-24 12:56               ` Laszlo Ersek
2014-09-24 17:55                 ` Junio C Hamano
2014-09-23 20:17   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).