]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb/corelow: Fix use-after-free in gdb_read_core_file_mappings
authorLancelot SIX <lancelot.six@amd.com>
Mon, 13 Oct 2025 14:11:09 +0000 (15:11 +0100)
committerLancelot SIX <lancelot.six@amd.com>
Tue, 14 Oct 2025 14:20:18 +0000 (15:20 +0100)
commit93f536d813c41527e8c939a5f8a90a4b37a5abab
tree586033ab919a332ddc5c51fb44d66d08a234c718
parent96d73418e905d53a97bbc0b05cb95698aefb8175
gdb/corelow: Fix use-after-free in gdb_read_core_file_mappings

A recent refactor (fc8e5a565b3 -- gdb: make structured core file
mappings processing global) in gdb/corelow.c:gdb_read_core_file_mappings
introduced a use-after-free bug detected by address sanitizer.

In this change, a cache is built which holds addresses to elements of a
std::vector.  However, as elements as inserted in the vector, the
addresses in the cache should be invalidated, but are not, leading to
the use-after-free issue.

This patch proposes to store the index in the vector in the cache
instead of the address of the element, solving the invalidation issue.
An alternative approach could be to use a std::list which does not need
invalidation of addresses/references/iterators as the container is
grown.

Change-Id: Ib57d87c5d0405ffa3b7d38557fb33f7283c5d063
Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/corelow.c