aboutsummaryrefslogtreecommitdiff
path: root/gdb/elfread.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2022-12-06 12:07:12 -0700
committerTom Tromey <tromey@adacore.com>2023-04-13 13:58:35 -0600
commitf96328accde1e6302b62aa880675594618079cb3 (patch)
tree4ed79fe1a3f483cdf92db1dd2d530658cb68f68e /gdb/elfread.c
parent546c7898dccb204eb56c8ed7c5b707c75de31b53 (diff)
downloadgdb-f96328accde1e6302b62aa880675594618079cb3.zip
gdb-f96328accde1e6302b62aa880675594618079cb3.tar.gz
gdb-f96328accde1e6302b62aa880675594618079cb3.tar.bz2
Avoid double-free with debuginfod
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
Diffstat (limited to 'gdb/elfread.c')
-rw-r--r--gdb/elfread.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 5577149..0305bf21 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1232,10 +1232,12 @@ elf_symfile_read_dwarf2 (struct objfile *objfile,
if (!debugfile.empty ())
{
- gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ()));
+ gdb_bfd_ref_ptr debug_bfd
+ (symfile_bfd_open_no_error (debugfile.c_str ()));
- symbol_file_add_separate (debug_bfd, debugfile.c_str (),
- symfile_flags, objfile);
+ if (debug_bfd != nullptr)
+ symbol_file_add_separate (debug_bfd, debugfile.c_str (),
+ symfile_flags, objfile);
}
else
{
@@ -1255,13 +1257,12 @@ elf_symfile_read_dwarf2 (struct objfile *objfile,
if (fd.get () >= 0)
{
/* File successfully retrieved from server. */
- gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (symfile_path.get ()));
+ gdb_bfd_ref_ptr debug_bfd
+ (symfile_bfd_open_no_error (symfile_path.get ()));
- if (debug_bfd == nullptr)
- warning (_("File \"%s\" from debuginfod cannot be opened as bfd"),
- filename);
- else if (build_id_verify (debug_bfd.get (), build_id->size,
- build_id->data))
+ if (debug_bfd != nullptr
+ && build_id_verify (debug_bfd.get (), build_id->size,
+ build_id->data))
{
symbol_file_add_separate (debug_bfd, symfile_path.get (),
symfile_flags, objfile);