From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Philip Oakley <philipoakley@iee.org>,
Stefan Naewe <stefan.naewe@gmail.com>,
git@vger.kernel.org, Stefan Beller <stefanbeller@googlemail.com>
Subject: Re: [PATCH] revision.c: fix possible null pointer access
Date: Fri, 4 Dec 2015 18:32:55 -0500 [thread overview]
Message-ID: <20151204233255.GD15064@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq610ete8x.fsf@gitster.mtv.corp.google.com>
On Fri, Dec 04, 2015 at 07:39:10AM -0800, Junio C Hamano wrote:
> > But you can't do that computation (in the error case under
> > consideration). Null can't be added to anything (as far as the
> > implications of the standards go). These are horrid gotchas because
> > they go against the grain of all that binary arithmetic and
> > simplifications we learnt long ago.
>
> Yeah, but in that hunk that does check !tree, because the function
> can be fed a NULL, the computed result assigned to object, which is
> undefined, is never used ;-)
>
> Of course, there used to be exotic platforms that are still standard
> compliant that triggered a trap when such a pointer computation was
> made (rather, such a bogus pointer was assigned to a pointer
> variable). I do not think anybody attempted to port Git to such a
> platform, but I agree that it is better to "fix" such a codepath, if
> only to stop wasting time dealing with them discussing with language
> lawyers ;-)
FWIW, I'd worry much more about compilers which do aggressive
optimizations based on language-lawyering (e.g., removing the null-check
as dead code, which is legal according to the standard because after you
computed the pointer based on it, it's all undefined behavior).
I don't think that changes your conclusion, though:
> So as I said in my review, the first hunk is a reject, the second
> one is OK.
-Peff
next prev parent reply other threads:[~2015-12-04 23:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-03 19:32 [PATCH] revision.c: fix possible null pointer access Stefan Naewe
2015-12-03 20:06 ` Junio C Hamano
2015-12-03 21:15 ` Stefan Naewe
2015-12-03 21:34 ` Philip Oakley
2015-12-03 22:17 ` Stefan Beller
2015-12-04 15:39 ` Junio C Hamano
2015-12-04 23:32 ` Jeff King [this message]
2015-12-05 15:27 ` [PATCH v2] " Stefan Naewe
2015-12-07 20:31 ` Junio C Hamano
2015-12-07 21:54 ` Johannes Sixt
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=20151204233255.GD15064@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=philipoakley@iee.org \
--cc=stefan.naewe@gmail.com \
--cc=stefanbeller@googlemail.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).