From: "Carlos Martín Nieto" <cmn@elego.de>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
git@vger.kernel.org, Erik Faye-Lund <kusmabite@gmail.com>
Subject: Re: [PATCH] system_path: use a static buffer
Date: Mon, 21 Mar 2011 16:26:29 +0100 [thread overview]
Message-ID: <1300721194.2583.22.camel@bee.lab.cmartin.tk> (raw)
In-Reply-To: <20110321111414.GD16334@sigill.intra.peff.net>
On lun, 2011-03-21 at 07:14 -0400, Jeff King wrote:
> On Mon, Mar 21, 2011 at 10:56:19AM +0100, Carlos Martín Nieto wrote:
>
> > On vie, 2011-03-18 at 00:25 -0700, Junio C Hamano wrote:
> > > Carlos Martín Nieto <cmn@elego.de> writes:
> > >
> > > > + ret = snprintf(buf, sizeof(buf), "%s/%s", prefix, path);
> > > > + if (ret >= sizeof(buf))
> > > > + die("system path too long for %s", path);
> > > > + else if (ret < 0)
> > > > + die_errno("encoding error");
> > >
> > > POSIX says snprintf() should set errno in this case, and your use of
> > > die_errno() would show that information, but what is "encoding error"?
> > >
> > > Just being curious, as I suspect that "snprintf() returned an error" may
> > > be more appropriate, if the answer is "I don't know what kind of error it
> > > is, but snprintf() found something faulty while encoding so I chose to
> > > call it encoding error".
> >
> > My manpage says snprintf returns -1 if there was an output or encoding
> > error. As there couldn't be an output error because it's writing to
> > memory and we can't output what snprintf chocked on because whatever
> > die_errno uses will also choke on it, I just put "encoding error". I'd
> > put "error assembling system path" as the actual error message, I guess.
>
> FWIW, we don't catch snprintf failures in 99% of the calls in git. Most
> calls just ignore the return value, and some even directly use the
> return value to add to a length. The one place that actually does check
> for the error is strbuf_vaddf, which just says "your vsnprintf is
> broken" and dies.
It's not actually likely we'll ever meet this error if the only one
allowed to set the format string is the programmer (and to do otherwise
is a security risk).
>
> So I'm not sure how much we really care about this error code path. If
> anything, we should be replacing all of the calls with something like:
>
> static const char buggy_sprintf_msg[] =
> "BUG: vsnprintf returned %d; either we fed it a bogus format string\n"
> "(our bug) or your libc is buggy and returns an error when it should\n"
> "tell us how much space is needed. The format string was:\n"
> "%s\n";
> int xsnprintf(char *out, size_t size, const char *fmt, ...)
> {
> va_list ap;
> int r;
>
> va_start(ap, fmt);
> r = vsnprintf(out, size, fmt, ap);
> va_end(ap);
>
> if (r < 0)
> die(buggy_sprintf_msg, r, fmt);
> return r;
> }
Or we could overload (#define) snprintf and replace it with the
paranoid. It'd go nicely with the vsnprintf that tries to work around
the Windows implementation.
I don't feel that strongly we should have the extra check there, seeing
how it's rare and not checked anywhere else.
cmn
next prev parent reply other threads:[~2011-03-21 15:26 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-14 19:18 [PATCH 0/3] Fix some errors reported by valgrind Carlos Martín Nieto
2011-03-14 19:18 ` [PATCH 1/3] make_absolute_path: Don't try to copy a string to itself Carlos Martín Nieto
2011-03-14 20:02 ` Jeff King
2011-03-14 20:25 ` Junio C Hamano
2011-03-14 22:02 ` Carlos Martín Nieto
2011-03-14 22:58 ` Junio C Hamano
2011-03-15 11:59 ` Carlos Martín Nieto
2011-03-15 12:40 ` Carlos Martín Nieto
2011-03-15 17:02 ` Junio C Hamano
2011-03-15 17:27 ` Carlos Martín Nieto
2011-03-16 14:16 ` Nguyen Thai Ngoc Duy
2011-03-16 14:49 ` Carlos Martín Nieto
2011-03-16 14:58 ` Nguyen Thai Ngoc Duy
2011-03-16 14:04 ` Nguyen Thai Ngoc Duy
2011-03-16 15:08 ` Carlos Martín Nieto
2011-03-14 19:18 ` [PATCH 2/3] setup_path(): Free temporary buffer Carlos Martín Nieto
2011-03-14 20:09 ` Jeff King
2011-03-14 22:18 ` Carlos Martín Nieto
2011-03-16 11:26 ` [PATCH] system_path: use a static buffer Carlos Martín Nieto
2011-03-16 15:58 ` Erik Faye-Lund
2011-03-16 16:24 ` Carlos Martín Nieto
2011-03-16 16:33 ` Carlos Martín Nieto
2011-03-16 20:43 ` Junio C Hamano
2011-03-17 11:01 ` Carlos Martín Nieto
2011-03-17 14:24 ` Carlos Martín Nieto
2011-03-18 7:25 ` Junio C Hamano
2011-03-21 9:56 ` Carlos Martín Nieto
2011-03-21 11:14 ` Jeff King
2011-03-21 15:26 ` Carlos Martín Nieto [this message]
2011-03-21 15:51 ` Jeff King
2011-03-21 15:57 ` Carlos Martín Nieto
2011-03-18 10:34 ` Nguyen Thai Ngoc Duy
2011-03-18 11:38 ` PATH_MAX (Re: [PATCH] system_path: use a static buffer) Jonathan Nieder
2011-03-18 11:54 ` Nguyen Thai Ngoc Duy
2011-03-21 9:47 ` Carlos Martín Nieto
2011-03-21 12:37 ` Lasse Makholm
2011-03-21 11:19 ` Nguyen Thai Ngoc Duy
2011-03-18 11:39 ` [PATCH 1/2] wrapper.c: add xgetcwd() Nguyễn Thái Ngọc Duy
2011-03-18 11:39 ` [PATCH 2/2] setup_gently: use xgetcwd() Nguyễn Thái Ngọc Duy
2011-03-14 20:14 ` [PATCH 2/3] setup_path(): Free temporary buffer Junio C Hamano
2011-03-14 22:01 ` Carlos Martín Nieto
2011-03-15 1:12 ` Jeff King
2011-03-15 9:32 ` [PATCH] t/README: Add a note about running commands under valgrind Carlos Martín Nieto
2011-03-15 17:06 ` Junio C Hamano
2011-03-15 17:08 ` Carlos Martín Nieto
2011-03-14 19:18 ` [PATCH 3/3] clone: Free a few paths Carlos Martín Nieto
2011-03-14 19:45 ` Jonathan Nieder
2011-03-18 7:25 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2011-03-31 14:36 [PATCH] system_path: use a static buffer Carlos Martín Nieto
2011-03-31 22:42 ` Junio C Hamano
2011-03-31 23:23 ` Carlos Martín Nieto
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=1300721194.2583.22.camel@bee.lab.cmartin.tk \
--to=cmn@elego.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kusmabite@gmail.com \
--cc=peff@peff.net \
/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).