Skip to contentSkip to conversation

Die for an early EOF in a file reading loop

PATCH New Heikki Orsila 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
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(-)
combine-diff.c +2 -2
index 0e19cba..a4269f6 100644
@@ -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;
 			}
Signature · 1 line
1.5.4.4