public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "Willgerodt, Felix" <felix.willgerodt@intel.com>
To: Alan Modra <amodra@gmail.com>
Cc: "binutils@sourceware.org" <binutils@sourceware.org>
Subject: RE: [PATCH 1/1] libctf: Fix double free in ctf_link_add_cu_mapping.
Date: Thu, 8 Dec 2022 07:47:09 +0000	[thread overview]
Message-ID: <MN2PR11MB4566EADBC0D722A344FEA3D68E1D9@MN2PR11MB4566.namprd11.prod.outlook.com> (raw)
In-Reply-To: <Y5E8bWk4cIGs3jI0@squeak.grove.modra.org>

> -----Original Message-----
> From: Alan Modra <amodra@gmail.com>
> Sent: Donnerstag, 8. Dezember 2022 02:23
> To: Willgerodt, Felix <felix.willgerodt@intel.com>
> Cc: binutils@sourceware.org
> Subject: Re: [PATCH 1/1] libctf: Fix double free in ctf_link_add_cu_mapping.
> 
> On Wed, Dec 07, 2022 at 03:11:37PM +0100, Felix Willgerodt via Binutils
> wrote:
> > This fixes a potential double free which can occur if we jump to
> > oom_noerrno after the first free.
> >
> > I am not very familiar with libctf, so any comments are welcome.
> > I am wondering if the right solution wouldn't be to free both t and f before
> > the "return 0".  But I didn't fully understand the code and saw that other
> > users of ctf_dynhash_insert() also don't free the key manually.
> 
> No, they can't be freed if successfully inserted into the hash table,
> but "t" should indeed be freed if already inserted.  I'm applying the
> following fix.
> 
> 	* ctf-link.c (ctf_link_add_cu_mapping): Set t NULL after free.
> 
> diff --git a/libctf/ctf-link.c b/libctf/ctf-link.c
> index 702f2b4d5fe..902b4408cd6 100644
> --- a/libctf/ctf-link.c
> +++ b/libctf/ctf-link.c
> @@ -431,7 +431,10 @@ ctf_link_add_cu_mapping (ctf_dict_t *fp, const char
> *from, const char *to)
>  	}
>      }
>    else
> -    free (t);
> +    {
> +      free (t);
> +      t = NULL;
> +    }
> 
>    if (ctf_dynhash_insert (one_out, f, NULL) < 0)
>      {
> 
> 
> --
> Alan Modra
> Australia Development Lab, IBM

Thanks, that looks fine to me as well.

Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  reply	other threads:[~2022-12-08  7:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07 14:11 Felix Willgerodt
2022-12-08  1:22 ` Alan Modra
2022-12-08  7:47   ` Willgerodt, Felix [this message]
2022-12-15 15:26   ` Nick Alcock

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=MN2PR11MB4566EADBC0D722A344FEA3D68E1D9@MN2PR11MB4566.namprd11.prod.outlook.com \
    --to=felix.willgerodt@intel.com \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).