Skip to content

Commit 5743350

Browse files
meyeringgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bac9c06 commit 5743350

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

rerere.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ static void read_rr(struct string_list *rr)
4242
name = xstrdup(buf);
4343
if (fgetc(in) != '\t')
4444
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+
}
4753
if (i == sizeof(buf))
4854
die("filename too long");
4955
string_list_insert(rr, buf)->util = name;

0 commit comments

Comments
 (0)