Skip to content

Commit

Permalink
git-apply: safety fixes
Browse files Browse the repository at this point in the history
This was triggered by me testing the "@@" numbering shorthand by GNU
patch, which not only showed that git-apply thought it meant the number
was duplicated (when it means that the second number is 1), but my tests
showed than when git-apply mis-understood the number, it would then not
raise an alarm about it if the patch ended early.

Now, this doesn't actually _matter_, since with a three-line context, the
only case that "x,1" will be shorthanded to "x" is when x itself is 1 (in
which case git-apply got it right), but the fact that git-apply would also
silently accept truncated patches was a missed opportunity for additional
sanity-checking.

So make git-apply refuse to look at a patch fragment that ends early.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Mar 26, 2006
1 parent 6a1640f commit c150462
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ static int parse_range(const char *line, int len, int offset, const char *expect
line += digits;
len -= digits;

*p2 = *p1;
*p2 = 1;
if (*line == ',') {
digits = parse_num(line+1, p2);
if (!digits)
Expand Down Expand Up @@ -901,6 +901,8 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
break;
}
}
if (oldlines || newlines)
return -1;
/* If a fragment ends with an incomplete line, we failed to include
* it in the above loop because we hit oldlines == newlines == 0
* before seeing it.
Expand Down

0 comments on commit c150462

Please sign in to comment.