Skip to content

Commit

Permalink
Die for an early EOF in a file reading loop
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Heikki Orsila authored and Junio C Hamano committed Apr 28, 2008
1 parent e8729f5 commit f0ec47b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions combine-diff.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f0ec47b

Please sign in to comment.