threads / patch / 13282

patchDie for an early EOF in a file reading loop

Subject: [PATCH] Die for an early EOF in a file reading loop

## tl;dr

One message between Apr 27, 2008 and Apr 27, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Heikki Orsila· Apr 27, 2008, 14:07 UTC · lore

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(-)
Show changes to combine-diff.c +2 −2
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

← back to recent threads