diff options
author | Jan Vrany <jan.vrany@labware.com> | 2022-12-12 22:13:27 +0000 |
---|---|---|
committer | Jan Vrany <jan.vrany@labware.com> | 2022-12-12 22:13:27 +0000 |
commit | 361e5e947e5193838919afe59ec3961d4dde40ea (patch) | |
tree | fce9c2945e509caf524abb68687b4b75ffd16220 | |
parent | b99ceddc917ab623cfe663c3aab5cc45e3b98b57 (diff) | |
download | gdb-users/jv/try-fix-use-after-free-fixup-v01.zip gdb-users/jv/try-fix-use-after-free-fixup-v01.tar.gz gdb-users/jv/try-fix-use-after-free-fixup-v01.tar.bz2 |
gdb: fix command lookup in execute_command ()users/jv/try-fix-use-after-free-fixup-v01
Commit b5661ff2 ("gdb: fix possible use-after-free when
executing commands") used lookup_cmd_exact () to lookup
command again after its execution to avoid possible
use-after-free error.
However this change broke test gdb.base/define.exp which
defines a post-hook for subcommand ("target testsuite").
In this case, lookup_cmd_exact () returned NULL because
there's no command 'testsuite' in top-level commands.
This commit fixes this case by looking up the command again
using the original command line via lookup_cmd ().
-rw-r--r-- | gdb/top.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -655,11 +655,6 @@ execute_command (const char *p, int from_tty) } } - /* Remember name of the command. This is needed later when - executing command post-hooks to handle the case when command - is redefined or removed during it's execution. See below. */ - std::string c_name (c->name); - /* If this command has been pre-hooked, run the hook first. */ execute_cmd_pre_hook (c); @@ -702,7 +697,8 @@ execute_command (const char *p, int from_tty) We need to lookup the command again since during its execution, a command may redefine itself. In this case, C pointer becomes invalid so we need to look it up again. */ - c = lookup_cmd_exact (c_name.c_str (), cmdlist); + const char *cmd2 = cmd_start; + c = lookup_cmd (&cmd2, cmdlist, "", nullptr, 1, 1); if (c != nullptr) execute_cmd_post_hook (c); |