git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
HOHeikki Orsila <heikki.orsila@iki.fi>
Date
Apr 27, 2008, 14:07 UTC
Message-ID
<20080427140724.GA26018@zakalwe.fi>

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
Message 1 of 1 in “Die for an early EOF in a file reading loop”
  1. Die for an early EOF in a file reading loopHeikki Orsila, Apr 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.