From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 04/13] gdb: fix crash in "maint canonicalize" without argument
Date: Tue, 20 Oct 2026 12:17:26 -0400 [thread overview]
Message-ID: <20261020162054.2140671-5-simon.marchi@efficios.com> (raw)
In-Reply-To: <20261020162054.2140671-1-simon.marchi@efficios.com>
Running "maint canonicalize" without an argument crashes GDB:
$ ./gdb -nx -q --data-directory=data-directory -ex "maint canon" -batch
/home/smarchi/src/binutils-gdb/gdb/cp-support.c:105:27: runtime error: load of null pointer of type 'const char'
This message is from UBSan, otherwise we get a segfault.
maintenance_canonicalize passes the NULL ARGS straight to
cp_canonicalize_string. Error out with error_no_arg if no argument is
given.
Add a test in gdb.base/maint.exp.
Change-Id: I2924a6e8d2a0a5ea77bdee5595a75c8c0fb59673
---
gdb/maint.c | 3 +++
gdb/testsuite/gdb.base/maint.exp | 1 +
2 files changed, 4 insertions(+)
diff --git a/gdb/maint.c b/gdb/maint.c
index 22954f624efe..7864458ba136 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -118,6 +118,9 @@ maintenance_demangle (const char *args, int from_tty)
static void
maintenance_canonicalize (const char *args, int from_tty)
{
+ if (args == nullptr)
+ error_no_arg (_("name"));
+
gdb::unique_xmalloc_ptr<char> canon = cp_canonicalize_string (args);
if (canon == nullptr)
gdb_printf ("No change.\n");
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index f0c183c8c417..d13dab21fbe9 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -456,5 +456,6 @@ gdb_test "maint canonicalize int short" "canonical = short"
gdb_test "maint canonicalize fn<ty<int>>" \
"canonical = fn<ty<int> >"
gdb_test "maint canonical unsigned int" "No change\\."
+gdb_test "maint canonicalize" "Argument required \\(name\\)\\."
gdb_exit
--
2.56.0
next prev parent reply other threads:[~2026-10-20 16:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 16:17 [PATCH 00/13] Make the C++ name parser recognize more char literal forms Simon Marchi
2026-10-20 16:17 ` [PATCH 01/13] gdb: make demangle_parse_info own the memory its tree points into Simon Marchi
2026-10-20 16:17 ` [PATCH 02/13] gdb: remove p_allocated_size parameter of gdb_cplus_demangle_print Simon Marchi
2026-10-20 16:17 ` [PATCH 03/13] gdb: modernize mangled_name_to_comp and cp_class_name_from_physname Simon Marchi
2026-10-20 16:17 ` Simon Marchi [this message]
2026-10-20 16:17 ` [PATCH 05/13] gdb: move C++ name parser parsing selftest to its own test Simon Marchi
2026-10-20 16:17 ` [PATCH 06/13] gdb: check exact results in the canonicalize selftest Simon Marchi
2026-10-21 15:21 ` Tom Tromey
2026-10-21 15:48 ` Simon Marchi
2026-10-21 16:56 ` Tom Tromey
2026-10-21 17:01 ` Simon Marchi
2026-10-21 17:48 ` Tom Tromey
2026-10-22 16:28 ` Simon Marchi
2026-10-20 16:17 ` [PATCH 07/13] gdb: extract lex_char_literal from cpname_yylex Simon Marchi
2026-10-21 15:22 ` Tom Tromey
2026-10-20 16:17 ` [PATCH 08/13] gdb: remove \^ escape sequence support from C++ name parser Simon Marchi
2026-10-20 16:17 ` [PATCH 09/13] gdb: remove backslash-newline handling from cp_parse_escape Simon Marchi
2026-10-20 16:17 ` [PATCH 10/13] gdb: fix out-of-bounds reads in lex_char_literal Simon Marchi
2026-10-20 16:17 ` [PATCH 11/13] gdb: handle hexadecimal escapes in C++ name parser Simon Marchi
2026-10-20 16:17 ` [PATCH 12/13] gdb: handle character literal encoding prefixes " Simon Marchi
2026-10-20 16:17 ` [PATCH 13/13] gdb: handle universal character names " 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=20261020162054.2140671-5-simon.marchi@efficios.com \
--to=simon.marchi@efficios.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