rerere.c: diagnose a corrupt MERGE_RR when hitting EOF between TAB and '\0'
If we reach EOF after the SHA1-then-TAB, yet before the NUL that terminates each file name, we would fill the file name buffer with \255 bytes resulting from the repeatedly-failing fgetc (returns EOF/-1) and ultimately complain about "filename too long", because no NUL was encountered. Signed-off-by: Jim Meyering <jim@meyering.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jim Meyering committed
May 26, 2011 at 15:54 UTC
5743350f696745a48dfe7976c98dc8eb5c842d72
1 file changed
+8
-2
rerere.c
+8
-2
@@ -42,8 +42,14 @@ static void read_rr(struct string_list *rr)
42
name = xstrdup(buf);
43
if (fgetc(in) != '\t')
44
die("corrupt MERGE_RR");
45
- for (i = 0; i < sizeof(buf) && (buf[i] = fgetc(in)); i++)
46
- ; /* do nothing */
45
+ for (i = 0; i < sizeof(buf); i++) {
46
+ int c = fgetc(in);
47
+ if (c < 0)
48
+ die("corrupt MERGE_RR");
49
+ buf[i] = c;
50
+ if (c == 0)
51
+ break;
52
+ }
53
if (i == sizeof(buf))
54
die("filename too long");
55
string_list_insert(rr, buf)->util = name;