git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heikki Orsila <heikki.orsila@iki.fi>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] Die for an early EOF in a file reading loop
Date: Sun, 27 Apr 2008 17:07:24 +0300	[thread overview]
Message-ID: <20080427140724.GA26018@zakalwe.fi> (raw)

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

                 reply	other threads:[~2008-04-27 14:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080427140724.GA26018@zakalwe.fi \
    --to=heikki.orsila@iki.fi \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).