public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb/gdb-13-branch] gdb: fix command lookup in execute_command ()
@ 2022-12-20 19:10 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2022-12-20 19:10 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a47dacc45bd8538e0a4c687e3d11468a51519a55

commit a47dacc45bd8538e0a4c687e3d11468a51519a55
Author: Jan Vrany <jan.vrany@labware.com>
Date:   Mon Dec 19 11:24:36 2022 +0000

    gdb: fix command lookup in execute_command ()
    
    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 ().
    
    Approved-By: Simon Marchi <simon.marchi@efficios.com>
    (cherry picked from commit 37e5833da583310268dc1b04fc6839e81b987897)

Diff:
---
 gdb/top.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/gdb/top.c b/gdb/top.c
index 45e65beb3b3..b732f29653f 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -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);
 
@@ -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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-20 19:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-20 19:10 [binutils-gdb/gdb-13-branch] gdb: fix command lookup in execute_command () Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).