diff options
author | Guinevere Larsen <guinevere@redhat.com> | 2025-04-29 11:39:56 -0300 |
---|---|---|
committer | Guinevere Larsen <guinevere@redhat.com> | 2025-04-30 09:15:32 -0300 |
commit | aab91c55c3371b459f923138f2a910e0d223f229 (patch) | |
tree | 9a8752d3be1f2eeac86cb35f0f577a735338f745 /gdb/progspace.c | |
parent | 0ecc474b769473cb0b402e6a1e1d9788f9d538ac (diff) | |
download | binutils-aab91c55c3371b459f923138f2a910e0d223f229.zip binutils-aab91c55c3371b459f923138f2a910e0d223f229.tar.gz binutils-aab91c55c3371b459f923138f2a910e0d223f229.tar.bz2 |
gdb: Stop exec_close looking like a UAF weakness
A recent static analyzer run flagged that program_space::exec_close
could be using a pointer after it has been freed. This is not true, as
the pointer is never dereferenced, the address is used for comparisons.
However, to avoid false positives from static analyzers (or bogus
security bugs), this commit makes the code stop looking like a UAF by
moving the unique_ptr into a local unique_ptr, so that there is no way
someone would think memory could be used after being freed.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/progspace.c')
-rw-r--r-- | gdb/progspace.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/gdb/progspace.c b/gdb/progspace.c index 569dfc8..fcfdbd7 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -202,12 +202,14 @@ program_space::exec_close () if (ebfd != nullptr) { /* Removing target sections may close the exec_ops target. - Clear ebfd before doing so to prevent recursion. */ - bfd *saved_ebfd = ebfd.get (); + Clear ebfd before doing so to prevent recursion. We + move it to another ref_ptr instead of saving it to a raw + pointer to avoid it looking like possible use-after-free. */ + gdb_bfd_ref_ptr saved_ebfd = std::move(ebfd); ebfd.reset (nullptr); ebfd_mtime = 0; - remove_target_sections (saved_ebfd); + remove_target_sections (saved_ebfd.get ()); m_exec_filename.reset (); } |