Skip to content

Commit c150462

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
git-apply: safety fixes
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>
1 parent 6a1640f commit c150462

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

apply.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ static int parse_range(const char *line, int len, int offset, const char *expect
693693
line += digits;
694694
len -= digits;
695695

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

0 commit comments

Comments
 (0)