From f0ec47b8e7f46e17e6b6fe1cead728fa24477e43 Mon Sep 17 00:00:00 2001 From: Heikki Orsila Date: Sun, 27 Apr 2008 17:07:24 +0300 Subject: 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 Signed-off-by: Junio C Hamano --- combine-diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'combine-diff.c') diff --git a/combine-diff.c b/combine-diff.c index 0e19cbaacc..f1e7a4d5d9 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -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; } -- cgit v1.2.1