From 7acceff377e79fea0a9f2ce394de7b980e6ad464 Mon Sep 17 00:00:00 2001
From: Heikki Orsila <heikki.orsila@iki.fi>
Date: Sun, 27 Apr 2008 16:56:22 +0300
Subject: [PATCH] Die for an early EOF in a file reading loop
Status: RO
Content-Length: 744
Lines: 25

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>
---
 combine-diff.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/combine-diff.c b/combine-diff.c
index 0e19cba..a4269f6 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -719,8 +719,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 			while (sz < len) {
 				ssize_t done = xread(fd, result+sz, len-sz);
 				if (done == 0)
-					break;
-				if (done < 0)
+					die("early EOF '%s'", elem->path);
+				else if (done < 0)
 					die("read error '%s'", elem->path);
 				sz += done;
 			}
-- 
1.5.4.4


