Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: handle missing arguments to 'maint test-remote-args'
@ 2026-06-02 14:50 Andrew Burgess
  2026-06-02 15:01 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2026-06-02 14:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

I noticed that the 'maint test-remote-args' command, implemented by
the test_remote_args_command function in remote.c, contains this code:

  static void
  test_remote_args_command (const char *args, int from_tty)
  {
    std::vector<std::string> split_args = gdb::remote_args::split (args);
    ... etc ...

The problem here is that gdb::remote_args::split expects a std::string,
and so ends up creating a std::string from ARGS.  However, ARGS can be
NULL, e.g. if a user does this:

  (gdb) maint test-remote-args

This ends up creating a std::string from a NULL pointer, which is
undefined behaviour.

Fix this by adding a check to test_remote_args_command, and throwing
an error if ARGS is NULL.  Add a new test to verify this case.

Additionally, fix a typo in the header comment for
test_remote_args_command.
---
 gdb/remote.c                                      | 5 ++++-
 gdb/testsuite/gdb.base/maint-test-remote-args.exp | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 735774903f3..2961664cf33 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -12767,12 +12767,15 @@ cli_packet_command (const char *args, int from_tty)
    The split and joined arguments are printed out.  Additionally, the
    joined arguments are split and joined a second time, and compared to the
    result of the first join, this provides some basic validation that GDB
-   sess the joined arguments as equivalent to the original argument
+   sees the joined arguments as equivalent to the original argument
    string.  */
 
 static void
 test_remote_args_command (const char *args, int from_tty)
 {
+  if (args == nullptr)
+    error (_("missing argument string"));
+
   std::vector<std::string> split_args = gdb::remote_args::split (args);
 
   gdb_printf ("Input (%s)\n", args);
diff --git a/gdb/testsuite/gdb.base/maint-test-remote-args.exp b/gdb/testsuite/gdb.base/maint-test-remote-args.exp
index b1a3e67abc6..22d9e81c25d 100644
--- a/gdb/testsuite/gdb.base/maint-test-remote-args.exp
+++ b/gdb/testsuite/gdb.base/maint-test-remote-args.exp
@@ -38,3 +38,6 @@ gdb_test "maint test-remote-args a b c" \
 	 "  \\(b\\)" \
 	 "  \\(c\\)" \
 	 "Output \\(a b c\\)"]
+
+gdb_test "maint test-remote-args" "^missing argument string" \
+    "command without an argument string"

base-commit: f577746edb4ca2678f69feb5e5848a646d5cd856
-- 
2.25.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: handle missing arguments to 'maint test-remote-args'
  2026-06-02 14:50 [PATCH] gdb: handle missing arguments to 'maint test-remote-args' Andrew Burgess
@ 2026-06-02 15:01 ` Tom Tromey
  2026-06-03  8:24   ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2026-06-02 15:01 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> Fix this by adding a check to test_remote_args_command, and throwing
Andrew> an error if ARGS is NULL.  Add a new test to verify this case.

Makes sense to me, thanks.
Approved-By: Tom Tromey <tom@tromey.com>

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: handle missing arguments to 'maint test-remote-args'
  2026-06-02 15:01 ` Tom Tromey
@ 2026-06-03  8:24   ` Andrew Burgess
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2026-06-03  8:24 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Fix this by adding a check to test_remote_args_command, and throwing
> Andrew> an error if ARGS is NULL.  Add a new test to verify this case.
>
> Makes sense to me, thanks.
> Approved-By: Tom Tromey <tom@tromey.com>

Pushed.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-03  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-02 14:50 [PATCH] gdb: handle missing arguments to 'maint test-remote-args' Andrew Burgess
2026-06-02 15:01 ` Tom Tromey
2026-06-03  8:24   ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox