git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
	Yaroslav Halchenko <yoh@onerussian.com>
Subject: [PATCH] strbuf: clear errno before calling getdelim(3)
Date: Thu, 10 Aug 2017 22:56:40 +0200	[thread overview]
Message-ID: <cd49ce13-db87-89c1-77e7-998fdb9442c3@web.de> (raw)
In-Reply-To: <20170810200502.rutab4z3ft7gcpjz@sigill.intra.peff.net>

getdelim(3) returns -1 at the end of the file and if it encounters an
error, but sets errno only in the latter case.  Set errno to zero before
calling it to avoid misdiagnosing an out-of-memory condition due to a
left-over value from some other function call.

Reported-by: Yaroslav Halchenko <yoh@onerussian.com>
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
Do we need to save and restore the original value of errno?  I doubt it,
but didn't think deeply about it, yet.

 strbuf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/strbuf.c b/strbuf.c
index 89d22e3b09..323c49ceb3 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -476,6 +476,7 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term)
 	/* Translate slopbuf to NULL, as we cannot call realloc on it */
 	if (!sb->alloc)
 		sb->buf = NULL;
+	errno = 0;
 	r = getdelim(&sb->buf, &sb->alloc, term, fp);
 
 	if (r > 0) {
-- 
2.14.0

  parent reply	other threads:[~2017-08-10 20:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-09 17:39 fatal: Out of memory, getdelim failed under NFS mounts Yaroslav Halchenko
2017-08-10 13:27 ` René Scharfe
2017-08-10 14:43   ` Yaroslav Halchenko
2017-08-10 19:44     ` René Scharfe
2017-08-10 18:56   ` Junio C Hamano
2017-08-10 19:44     ` Yaroslav Halchenko
2017-08-10 19:58     ` René Scharfe
2017-08-10 20:05       ` Jeff King
2017-08-10 20:29         ` Yaroslav Halchenko
2017-08-10 20:56         ` René Scharfe [this message]
2017-08-10 21:02           ` [PATCH] strbuf: clear errno before calling getdelim(3) Jeff King
2017-08-10 21:35             ` Yaroslav Halchenko
2017-08-10 21:41           ` Junio C Hamano
2017-08-11  7:50           ` Simon Ruderich
2017-08-11  8:52             ` René Scharfe
2017-08-12 10:02               ` Simon Ruderich
2017-08-12 11:57                 ` René Scharfe
2017-08-12 12:21                   ` René Scharfe
2017-08-13  4:32                   ` Jeff King
2017-08-13  5:51                     ` René Scharfe
2017-08-13  5:58                       ` Jeff King

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=cd49ce13-db87-89c1-77e7-998fdb9442c3@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=yoh@onerussian.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).