{"thread":{"id":"3723","subject":"More \"git-apply\" safety fixes","startedAt":"2006-03-25T21:28:28Z","lastAt":"2006-03-25T21:28:28Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"17952","messageId":"Pine.LNX.4.64.0603251321330.15714@g5.osdl.org","threadId":"3723","inReplyTo":null,"subject":"More \"git-apply\" safety fixes","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-03-25T21:28:28Z","receivedAt":"2006-03-25T21:28:28Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nThis was triggered by me testing the \"@@\" numbering shorthand by GNU \npatch, which not only showed that git-apply thought it meant the number \nwas duplicated (when it means that the second number is 1), but my tests \nshowed than when git-apply mis-understood the number, it would then not \nraise an alarm about it if the patch ended early.\n\nNow, this doesn't actually _matter_, since with a three-line context, the \nonly case that \"x,1\" will be shorthanded to \"x\" is when x itself is 1 (in \nwhich case git-apply got it right), but the fact that git-apply would also \nsilently accept truncated patches was a missed opportunity for additional \nsanity-checking.\n\nSo make git-apply refuse to look at a patch fragment that ends early.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n----\n\nIf you already applied the first hunk, just ignore that part, and apply \nthe second one that adds the test for oldlines/newlines being zero after \nthe patch.\n\nNeither of these two changes should matter for a well-formed patch, but \nit's definitely the right thing to do.\n\ndiff --git a/apply.c b/apply.c\nindex 2da225a..c50b3a6 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -693,7 +693,7 @@ static int parse_range(const char *line,\n \tline += digits;\n \tlen -= digits;\n \n-\t*p2 = *p1;\n+\t*p2 = 1;\n \tif (*line == ',') {\n \t\tdigits = parse_num(line+1, p2);\n \t\tif (!digits)\n@@ -901,6 +901,8 @@ static int parse_fragment(char *line, un\n \t\t\tbreak;\n \t\t}\n \t}\n+\tif (oldlines || newlines)\n+\t\treturn -1;\n \t/* If a fragment ends with an incomplete line, we failed to include\n \t * it in the above loop because we hit oldlines == newlines == 0\n \t * before seeing it.\n"}]}