aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2021-11-22 20:52:15 -0800
committerAndrew Burgess <aburgess@redhat.com>2021-11-24 10:27:53 +0000
commit5e97696c113e8ffa93e12df22e0d34c6984cc383 (patch)
tree8f94b966e7c448e676848984a8bafc144bed7264 /gdb
parent95db489df60d870f5f8f2b32debd6bb0b50c3c5e (diff)
downloadgdb-5e97696c113e8ffa93e12df22e0d34c6984cc383.zip
gdb-5e97696c113e8ffa93e12df22e0d34c6984cc383.tar.gz
gdb-5e97696c113e8ffa93e12df22e0d34c6984cc383.tar.bz2
gdb: fix crash when reading ECOFF debug information
In commit: commit 633cf2548bcd3dafe297e21a1dd3574240280d48 Date: Wed May 9 15:42:28 2018 -0600 Remove cleanups from mdebugread.c the following change was made in the function parse_partial_symbols in mdebugread.c: - fdr_to_pst = XCNEWVEC (struct pst_map, hdr->ifdMax + 1); - old_chain = make_cleanup (xfree, fdr_to_pst); + gdb::def_vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1); + fdr_to_pst = fdr_to_pst_holder.data (); The problem with this change is that XCNEWVEC calls xcalloc, which in turn calls calloc, and calloc zero initializes the allocated memory. In contrast, the new line gdb::def_vector<struct pst_map> specifically does not initialize the underlying memory. This is a problem because, later on in this same function, we increment the n_globals field within 'struct pst_map' objects stored in the vector. The incrementing is now being done from an uninitialized starting point. In this commit we switch from using gdb::def_vector to using std::vector, this alone should be enough to ensure that the fields are initialized to zero. However, for extra clarity, I have also added initial values in the 'struct pst_map' to make it crystal clear how the struct will start up. This issue was reported on the mailing list here: https://sourceware.org/pipermail/gdb-patches/2021-November/183693.html Co-Authored-By: Lightning <lightningth@gmail.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/mdebugread.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 0faff5f..9204d3d 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -386,9 +386,9 @@ mdebug_build_psymtabs (minimal_symbol_reader &reader,
struct pst_map
{
- legacy_psymtab *pst; /* the psymtab proper */
- long n_globals; /* exported globals (external symbols) */
- long globals_offset; /* cumulative */
+ legacy_psymtab *pst = nullptr; /* the psymtab proper */
+ long n_globals = 0; /* exported globals (external symbols) */
+ long globals_offset = 0; /* cumulative */
};
@@ -2365,7 +2365,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
/* Allocate the map FDR -> PST.
Minor hack: -O3 images might claim some global data belongs
to FDR -1. We`ll go along with that. */
- gdb::def_vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1);
+ std::vector<struct pst_map> fdr_to_pst_holder (hdr->ifdMax + 1);
fdr_to_pst = fdr_to_pst_holder.data ();
fdr_to_pst++;
{