Skip to content

Commit

Permalink
gdb: fix command lookup in execute_command ()
Browse files Browse the repository at this point in the history
Commit b5661ff ("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 ().

Approved-By: Simon Marchi <simon.marchi@efficios.com>
  • Loading branch information
janvrany committed Dec 19, 2022
1 parent 42f39fd commit 37e5833
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions gdb/top.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,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);

Expand Down Expand Up @@ -698,7 +693,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);

Expand Down

0 comments on commit 37e5833

Please sign in to comment.