apply: avoid possible bogus pointer
authorJeff King <peff@peff.net>
Thu, 24 Jul 2014 04:43:23 +0000 (00:43 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 24 Jul 2014 20:57:50 +0000 (13:57 -0700)
When parsing "index" lines from a git-diff, we look for a
space followed by the mode. If we don't have a space, then
we set our pointer to the end-of-line. However, we don't
double-check that our end-of-line pointer is valid (e.g., if
we got a truncated diff input), which could lead to some
wrap-around pointer arithmetic.

In most cases this would probably get caught by our "40 <
len" check later in the function, but to be on the safe
side, let's just use strchrnul to treat end-of-string the
same as end-of-line.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/apply.c
index 87439fad118a2671989120dd5993a17b4541e2db..5b7a3066adca5912b2ac2551a89f74531decb9aa 100644 (file)
@@ -1073,7 +1073,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
 
        line = ptr + 2;
        ptr = strchr(line, ' ');
-       eol = strchr(line, '\n');
+       eol = strchrnul(line, '\n');
 
        if (!ptr || eol < ptr)
                ptr = eol;