aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorGuinevere Larsen <guinevere@redhat.com>2024-12-05 10:19:59 -0300
committerGuinevere Larsen <guinevere@redhat.com>2024-12-06 14:36:58 -0300
commit5e738d49145b8c262734c23cbbb840475118ffa6 (patch)
treee3a6b04cb701bc4eb4266435e56c569a2d2a9d3c /gdb/symfile.c
parentb2682eade4db993bc8231007ba94aec4e4728c61 (diff)
downloadbinutils-5e738d49145b8c262734c23cbbb840475118ffa6.zip
binutils-5e738d49145b8c262734c23cbbb840475118ffa6.tar.gz
binutils-5e738d49145b8c262734c23cbbb840475118ffa6.tar.bz2
gdb: Fix use-after-free when an objfile has no symbols to load
The recent commit <HASH> moved an initialization of an objfile_holder in syms_from_objfile_1 much earlier in the function, to better deal with when GDB is unable to read the objfile format. However, there is an early exit from syms_from_objfile_1 when the objfile can be understood, but has no symbols. That was not releasing the objfile_holder, so the objfile was being unlinked from the program space, but the process of reading the objfile was being continued, leading to use-after-frees flagged by the Address Sanitizer. This commit fixes that UAF by making the objfile_holder release the objfile right before the early exit. This commit also changes the test gdb.base/dump.exp since that was the original test that flagged the UAF, but at the end of the test the generated files were being deleted, meaning we couldn't redo the test manually after the fact. That final deletion was removed Reported-by: Simon Marchi <simark@simark.ca> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 3fd6c8d..28c0d46 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -901,6 +901,10 @@ syms_from_objfile_1 (struct objfile *objfile,
int num_sections = gdb_bfd_count_sections (objfile->obfd.get ());
objfile->section_offsets.assign (num_sections, 0);
+
+ /* Release the objfile unique pointer, since nothing went wrong
+ in reading it. */
+ objfile_holder.release ();
return;
}