From: Tom Tromey <tom@tromey.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Tom Tromey <tom@tromey.com>,
gdb-patches@sourceware.org,
Joel Brobecker <brobecker@adacore.com>
Subject: Re: [PATCH 3/3] Cache the result of find_file_and_directory
Date: Sun, 05 Dec 2021 13:17:38 -0700 [thread overview]
Message-ID: <874k7mu7q5.fsf@tromey.com> (raw)
In-Reply-To: <adfcb528-41f9-3da0-2d19-9e4acfb0d4a4@polymtl.ca> (Simon Marchi's message of "Sat, 4 Dec 2021 22:47:24 -0500")
>> Sorry about that. I'll fix it soon. Or you can back it out if you
>> prefer.
Simon> I'm not personally affected so I do not mind, I can wait for the fix.
Here is what I am checking in.
I was able to reproduce the failure with valgrind, and confirmed that
this patch fixes it.
Tom
commit 33af066d07d495c81c7c102125aec8dbac62c27b
Author: Tom Tromey <tom@tromey.com>
Date: Sun Dec 5 13:13:33 2021 -0700
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.
diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h
index 1a9ccf35829..c56922ff90d 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 @@ struct file_and_directory
/* 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 ff5758eb0a4..f2d7da7de52 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 ());
next prev parent reply other threads:[~2021-12-05 20:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 1:33 [PATCH 0/3] Refactor find_file_and_directory Tom Tromey
2021-11-30 1:33 ` [PATCH 1/3] Remove Irix case from find_file_and_directory Tom Tromey
2021-12-04 10:43 ` Joel Brobecker via Gdb-patches
2021-11-30 1:33 ` [PATCH 2/3] Move file_and_directory to new file and C++-ize Tom Tromey
2021-11-30 16:18 ` Lancelot SIX via Gdb-patches
2021-11-30 17:44 ` Tom Tromey
2021-12-04 10:38 ` Joel Brobecker via Gdb-patches
2021-12-04 18:22 ` Tom Tromey
2021-11-30 1:33 ` [PATCH 3/3] Cache the result of find_file_and_directory Tom Tromey
2021-12-04 10:42 ` Joel Brobecker via Gdb-patches
2021-12-04 18:22 ` Tom Tromey
2021-12-05 2:31 ` Simon Marchi via Gdb-patches
2021-12-05 3:46 ` Tom Tromey
2021-12-05 3:47 ` Simon Marchi via Gdb-patches
2021-12-05 20:17 ` Tom Tromey [this message]
2021-12-06 1:54 ` Simon Marchi via Gdb-patches
2021-12-07 4:30 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874k7mu7q5.fsf@tromey.com \
--to=tom@tromey.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox