mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
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>
This commit is contained in:
parent
e8729f5380
commit
f0ec47b8e7
|
@ -718,9 +718,9 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
|||
result = xmalloc(len + 1);
|
||||
while (sz < len) {
|
||||
ssize_t done = xread(fd, result+sz, len-sz);
|
||||
if (done == 0)
|
||||
break;
|
||||
if (done < 0)
|
||||
if (done == 0 && sz != len)
|
||||
die("early EOF '%s'", elem->path);
|
||||
else if (done < 0)
|
||||
die("read error '%s'", elem->path);
|
||||
sz += done;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue