public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Avoid double-free with debuginfod
Date: Tue, 13 Dec 2022 16:32:29 -0500	[thread overview]
Message-ID: <afb373ad-afaf-ea4a-79be-9fd451881cdd@simark.ca> (raw)
In-Reply-To: <20221212183852.1502020-1-tromey@adacore.com>

On 12/12/22 13:38, Tom Tromey via Gdb-patches wrote:
> PR gdb/29257 points out a possible double free when debuginfod is in
> use.  Aside from some ugly warts in the symbol code (an ongoing
> issue), the underlying issue in this particular case is that elfread.c
> seems to assume that symfile_bfd_open will return NULL on error,
> whereas in reality it throws an exception.  As this code isn't
> prepared for an exception, bad things result.
> 
> This patch fixes the problem by introducing a non-throwing variant of
> symfile_bfd_open and using it in the affected places.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29257

I don't know how the debuginfo tests in our testsuite work... would it
be easy to make a test that mimics the reproduction steps given in the
bug?  You would build an executable without debug info, then make an
empty file with the approrpriate name in the debuginfod cache.

> diff --git a/gdb/symfile.h b/gdb/symfile.h
> index ffd1acddfdb..61d69c4e412 100644
> --- a/gdb/symfile.h
> +++ b/gdb/symfile.h
> @@ -269,6 +269,11 @@ extern void set_initial_language (void);
>  
>  extern gdb_bfd_ref_ptr symfile_bfd_open (const char *);
>  
> +/* Like symfile_bfd_open, but will not throw an exception on error.
> +   Instead, it issues a warning and returns nullptr.  */
> +
> +extern gdb_bfd_ref_ptr symfile_bfd_open_no_error (const char *);

Maybe mark the function noexcept?

Simon

  reply	other threads:[~2022-12-13 21:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12 18:38 Tom Tromey
2022-12-13 21:32 ` Simon Marchi [this message]
2023-04-13 20:00   ` Tom Tromey

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=afb373ad-afaf-ea4a-79be-9fd451881cdd@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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 read-only IMAP folder(s) and NNTP newsgroup(s).