Skip to content

Commit 31bb6d3

Browse files
peffgitster
authored andcommitted
apply: avoid possible bogus pointer
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 649409b commit 31bb6d3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
10731073

10741074
line = ptr + 2;
10751075
ptr = strchr(line, ' ');
1076-
eol = strchr(line, '\n');
1076+
eol = strchrnul(line, '\n');
10771077

10781078
if (!ptr || eol < ptr)
10791079
ptr = eol;

0 commit comments

Comments
 (0)