]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: handle missing arguments to 'maint test-remote-args'
authorAndrew Burgess <aburgess@redhat.com>
Tue, 2 Jun 2026 14:34:36 +0000 (15:34 +0100)
committerAndrew Burgess <aburgess@redhat.com>
Wed, 3 Jun 2026 08:22:57 +0000 (09:22 +0100)
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.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/remote.c
gdb/testsuite/gdb.base/maint-test-remote-args.exp

index 735774903f3f094bed29c540f3a19a6e6f45aecc..2961664cf338feb93d1ef4938e36457b18f3a8f0 100644 (file)
@@ -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);
index b1a3e67abc610418472150cebb0a0a9188fc535a..22d9e81c25d3852ce210e522551554bb814f5d0c 100644 (file)
@@ -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"