From: "Michał Górny" <mgorny@gentoo.org>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] gpg-interface.c: Fix potentially freeing NULL values
Date: Fri, 17 Aug 2018 11:40:06 +0200 [thread overview]
Message-ID: <1534498806.1262.8.camel@gentoo.org> (raw)
In-Reply-To: <CAPig+cQVWY3+2aarYw=uXti0=1SW8boMPoYj1zatw1KKKVOqnQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2199 bytes --]
On Fri, 2018-08-17 at 05:28 -0400, Eric Sunshine wrote:
> On Fri, Aug 17, 2018 at 5:17 AM Michał Górny <mgorny@gentoo.org> wrote:
> > Fix signature_check_clear() to free only values that are non-NULL. This
> > especially applies to 'key' and 'signer' members that can be NULL during
> > normal operations, depending on exact GnuPG output. While at it, also
> > allow other members to be NULL to make the function easier to use,
> > even if there is no real need to account for that right now.
>
> free(NULL) is valid behavior[1] and much of the Git codebase relies upon it.
>
> Did you run into a case where it misbehaved?
Nope. I was actually wondering if it's expected, so I did a quick grep
to check whether git is checking pointers for non-NULL before free()ing,
and found at least one:
blame.c-static void drop_origin_blob(struct blame_origin *o)
blame.c-{
blame.c- if (o->file.ptr) {
blame.c: FREE_AND_NULL(o->file.ptr);
blame.c- }
blame.c-}
So I wrongly presumed it might be desirable. If it's not, that's fine
by me.
>
> [1]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
>
> > Signed-off-by: Michał Górny <mgorny@gentoo.org>
> > ---
> > diff --git a/gpg-interface.c b/gpg-interface.c
> > index 35c25106a..9aedaf464 100644
> > --- a/gpg-interface.c
> > +++ b/gpg-interface.c
> > @@ -15,9 +15,14 @@ static const char *gpg_program = "gpg";
> > void signature_check_clear(struct signature_check *sigc)
> > {
> > - FREE_AND_NULL(sigc->payload);
> > - FREE_AND_NULL(sigc->gpg_output);
> > - FREE_AND_NULL(sigc->gpg_status);
> > - FREE_AND_NULL(sigc->signer);
> > - FREE_AND_NULL(sigc->key);
> > + if (sigc->payload)
> > + FREE_AND_NULL(sigc->payload);
> > + if (sigc->gpg_output)
> > + FREE_AND_NULL(sigc->gpg_output);
> > + if (sigc->gpg_status)
> > + FREE_AND_NULL(sigc->gpg_status);
> > + if (sigc->signer)
> > + FREE_AND_NULL(sigc->signer);
> > + if (sigc->key)
> > + FREE_AND_NULL(sigc->key);
> > }
--
Best regards,
Michał Górny
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 963 bytes --]
next prev parent reply other threads:[~2018-08-17 9:40 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-17 9:17 [PATCH] gpg-interface.c: Fix potentially freeing NULL values Michał Górny
2018-08-17 9:28 ` Eric Sunshine
2018-08-17 9:40 ` Michał Górny [this message]
2018-08-17 13:02 ` [PATCH] refactor various if (x) FREE_AND_NULL(x) to just FREE_AND_NULL(x) Ævar Arnfjörð Bjarmason
2018-08-17 14:36 ` Duy Nguyen
2018-08-17 15:10 ` Duy Nguyen
2018-08-17 16:53 ` Junio C Hamano
2018-08-17 17:07 ` Junio C Hamano
2018-08-17 17:33 ` Jeff King
2018-08-17 17:39 ` Jeff King
2018-08-17 17:44 ` Jeff King
2018-08-17 18:29 ` Duy Nguyen
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=1534498806.1262.8.camel@gentoo.org \
--to=mgorny@gentoo.org \
--cc=git@vger.kernel.org \
--cc=sunshine@sunshineco.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).