@matheusbsbs / matheus-bagliano / commits / f0ec47b8e7
Fork 0

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>

Heikki Orsila committed Apr 27, 2008 at 17:07 UTC f0ec47b8e7f46e17e6b6fe1cead728fa24477e43
1 file changed +3 -3
combine-diff.c
+3 -3
@@ -718,9 +718,9 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
718 result = xmalloc(len + 1);
719 while (sz < len) {
720 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)
724 die("read error '%s'", elem->path);
725 sz += done;
726 }