Skip to content

Commit f0ec47b

Browse files
heikkiorsilagitster
authored andcommitted
Die for an early EOF in a file reading loop
The resulting data is zero terminated after the read loop, but the subsequent loop that scans for '\n' will overrun the buffer. Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e8729f5 commit f0ec47b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

combine-diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,9 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
718718
result = xmalloc(len + 1);
719719
while (sz < len) {
720720
ssize_t done = xread(fd, result+sz, len-sz);
721-
if (done == 0)
722-
break;
723-
if (done < 0)
721+
if (done == 0 && sz != len)
722+
die("early EOF '%s'", elem->path);
723+
else if (done < 0)
724724
die("read error '%s'", elem->path);
725725
sz += done;
726726
}

0 commit comments

Comments
 (0)