From: Luis Machado <luis.machado@arm.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] Fix crash with "maintenance print arc"
Date: Wed, 27 Apr 2022 11:07:53 +0100 [thread overview]
Message-ID: <20220427100753.364631-1-luis.machado@arm.com> (raw)
While doing something else, I noticed GDB crashed with
"maintenance print arc".
This happens because the code expects to find a "show" string pattern
within "maintenance print arc", since "arc" here is a prefix, and skip it.
In this case though, it won't find it, and we will have a bad pointer
getting dereferenced.
There is another part of the code with a similar assumption.
This patch hardens both code paths to prevent future crashes.
Regression-tested on x86_64 and aarch64 Linux Ubuntu 20.04.
---
gdb/cli/cli-setshow.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 213573e443e..3852a505cf5 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -712,7 +712,13 @@ cmd_show_list (struct cmd_list_element *list, int from_tty)
{
ui_out_emit_tuple optionlist_emitter (uiout, "optionlist");
std::string prefixname = list->prefixname ();
- const char *new_prefix = strstr (prefixname.c_str (), "show ") + 5;
+ const char *new_prefix = strstr (prefixname.c_str (), "show ");
+
+ /* If we've found a "show" string, remove it now. */
+ if (new_prefix != nullptr)
+ new_prefix += 5;
+ else
+ new_prefix = prefixname.c_str ();
if (uiout->is_mi_like_p ())
uiout->field_string ("prefix", new_prefix);
@@ -726,8 +732,15 @@ cmd_show_list (struct cmd_list_element *list, int from_tty)
{
/* If we find a prefix, output it (with "show " skipped). */
std::string prefixname = list->prefix->prefixname ();
- prefixname = (!list->prefix->is_prefix () ? ""
- : strstr (prefixname.c_str (), "show ") + 5);
+ const char *prefix = nullptr;
+
+ if (list->prefix->is_prefix ())
+ prefix = strstr (prefixname.c_str (), "show ");
+
+ /* If we've found a "show" string, remove it now. */
+ if (prefix != nullptr)
+ prefixname = prefix + 5;
+
uiout->text (prefixname);
}
uiout->field_string ("name", list->name);
--
2.25.1
next reply other threads:[~2022-04-27 10:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 10:07 Luis Machado [this message]
2022-04-27 10:43 ` Andrew Burgess
2022-04-27 11:00 ` Luis Machado
2022-04-28 15:27 ` Tom Tromey
2022-04-29 10:20 ` Andrew Burgess
2022-04-28 15:26 ` Tom Tromey
2022-04-29 8:58 ` Luis Machado
2022-04-29 10:18 ` Andrew Burgess
2022-04-29 10:39 ` Luis Machado
2022-04-29 11:25 ` Pedro Alves
2022-05-05 9:31 ` Luis Machado
2022-05-27 13:34 ` 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=20220427100753.364631-1-luis.machado@arm.com \
--to=luis.machado@arm.com \
--cc=gdb-patches@sourceware.org \
/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).