From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>, tom@tromey.com, luis.machado@arm.com
Subject: [PATCH] gdb: fix command lookup in execute_command ()
Date: Tue, 13 Dec 2022 11:22:41 +0000 [thread overview]
Message-ID: <20221213112241.621889-1-jan.vrany@labware.com> (raw)
In-Reply-To: <1a96057b-afd6-1e90-15c9-ee106a2998c7@arm.com>
Hi,
> I've spotted gdb.base/define.exp failing today, and bisection stopped in this particular
> patch.
> target testsuite
> one
> hello
> (gdb) FAIL: gdb.base/define.exp: target testsuite with hooks
My fault, I did not consider the case of hooks on subcommands
(I was not even conciously aware this is possible).
The below patch should fix this case - with it on my system
gdb.base/define.exp passes.
Alternatively I may just revert the commit until better solution
is found.
-- >8 --
Subject: [PATCH] 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 ().
---
gdb/top.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/gdb/top.c b/gdb/top.c
index 742997808bd..caa08d98cec 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -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);
--
2.35.1
next prev parent reply other threads:[~2022-12-13 11:23 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 14:20 [PATCH] gdb: fix possible use-after-free when executing commands Jan Vrany
2022-12-09 17:55 ` Tom Tromey
2022-12-12 15:05 ` Luis Machado
2022-12-12 15:08 ` Jan Vraný
2022-12-12 15:09 ` Luis Machado
2022-12-13 11:22 ` Jan Vrany [this message]
2022-12-13 15:05 ` [PATCH] gdb: fix command lookup in execute_command () Tom Tromey
2022-12-13 16:43 ` Simon Marchi
2022-12-13 18:48 ` Jan Vraný
2022-12-13 19:29 ` Simon Marchi
2022-12-14 11:07 ` [PATCH] gdb: fix command lookup in execute_command () commands" Jan Vrany
2022-12-14 15:35 ` Simon Marchi
2022-12-14 15:41 ` Jan Vraný
2022-12-14 15:59 ` Tom Tromey
2022-12-14 16:01 ` Simon Marchi
2022-12-14 18:05 ` Tom Tromey
2022-12-14 18:30 ` Simon Marchi
2022-12-14 22:01 ` Simon Marchi
2022-12-16 14:07 ` [PATCH] gdb: fix command lookup in execute_command () Jan Vraný
2022-12-16 16:47 ` Simon Marchi
2022-12-19 11:48 ` Jan Vraný
2022-12-19 14:46 ` Tom Tromey
2022-12-19 15:51 ` Jan Vraný
2022-12-20 19:10 ` Tom Tromey
2022-12-14 19:52 ` [PATCH] gdb: fix possible use-after-free when executing commands Simon Marchi
2022-12-14 20:39 ` Jan Vraný
2022-12-14 20:42 ` Simon Marchi
2022-12-15 12:57 ` Jan Vrany
2022-12-15 13:53 ` Simon Marchi
2022-12-15 14:51 ` Jan Vrany
2022-12-15 16:00 ` Simon Marchi
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=20221213112241.621889-1-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado@arm.com \
--cc=tom@tromey.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).