diff options
author | Tom Tromey <tom@tromey.com> | 2021-12-05 13:13:33 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-12-05 13:13:33 -0700 |
commit | 33af066d07d495c81c7c102125aec8dbac62c27b (patch) | |
tree | 8b5490d3eb5add969f8df4a9cf471f2fa1f7c2d9 /gdb/dwarf2 | |
parent | 843bf75416dd11d91a5d617f7a49f6e9e5025b42 (diff) | |
download | gdb-33af066d07d495c81c7c102125aec8dbac62c27b.zip gdb-33af066d07d495c81c7c102125aec8dbac62c27b.tar.gz gdb-33af066d07d495c81c7c102125aec8dbac62c27b.tar.bz2 |
Preserve artificial CU name in process_psymtab_comp_unit_reader
This fixes a use-after-free that Simon pointed out.
process_psymtab_comp_unit_reader was allocating an artificial name for
a CU, and then discarding it. However, this name was preserved in the
cached file_and_directory. This patch arranges for the allocated name
to be preserved there.
Diffstat (limited to 'gdb/dwarf2')
-rw-r--r-- | gdb/dwarf2/file-and-dir.h | 8 | ||||
-rw-r--r-- | gdb/dwarf2/read.c | 10 |
2 files changed, 11 insertions, 7 deletions
diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h index 1a9ccf3..c56922f 100644 --- a/gdb/dwarf2/file-and-dir.h +++ b/gdb/dwarf2/file-and-dir.h @@ -84,9 +84,10 @@ struct file_and_directory } /* Set the filename. */ - void set_name (const char *name) + void set_name (gdb::unique_xmalloc_ptr<char> name) { - m_name = name; + m_name_storage = std::move (name); + m_name = m_name_storage.get (); } private: @@ -94,6 +95,9 @@ private: /* The filename. */ const char *m_name; + /* Storage for the filename, if needed. */ + gdb::unique_xmalloc_ptr<char> m_name_storage; + /* The compilation directory. NULL if not known. If we needed to compute a new string, it will be stored in the comp_dir_storage member, and this will be NULL. Otherwise, points directly to the diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ff5758e..f2d7da7 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -6986,15 +6986,15 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, prepare_one_comp_unit (cu, comp_unit_die, pretend_language); /* Allocate a new partial symbol table structure. */ - gdb::unique_xmalloc_ptr<char> debug_filename; static const char artificial[] = "<artificial>"; file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu); if (strcmp (fnd.get_name (), artificial) == 0) { - debug_filename.reset (concat (artificial, "@", - sect_offset_str (per_cu->sect_off), - (char *) NULL)); - fnd.set_name (debug_filename.get ()); + gdb::unique_xmalloc_ptr<char> debug_filename + (concat (artificial, "@", + sect_offset_str (per_cu->sect_off), + (char *) NULL)); + fnd.set_name (std::move (debug_filename)); } pst = create_partial_symtab (per_cu, per_objfile, fnd.get_name ()); |