git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Die for an early EOF in a file reading loop
@ 2008-04-27 14:07 Heikki Orsila
  0 siblings, 0 replies; only message in thread
From: Heikki Orsila @ 2008-04-27 14:07 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

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>
---
Yes, I know it is highly improbable that the file size changes between 
fstat() and read(), but so is read error on media.

 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-27 14:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-27 14:07 [PATCH] Die for an early EOF in a file reading loop Heikki Orsila

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).