[gdb/breakpoints] Fix segfault for catch syscall -1
authorTom de Vries <tdevries@suse.de>
Fri, 5 Feb 2021 16:47:07 +0000 (17:47 +0100)
committerTom de Vries <tdevries@suse.de>
Fri, 5 Feb 2021 16:47:07 +0000 (17:47 +0100)
Using a hello world a.out, I run into a segfault:
...
$ gcc hello.c
$ gdb -batch a.out -ex "catch syscall -1" -ex r
Catchpoint 1 (syscall -1)
Aborted (core dumped)
...

Fix this by erroring out if a negative syscall number is used in the
catch syscall command.

Tested on x86_64-linux.

gdb/ChangeLog:

2021-02-05  Tom de Vries  <tdevries@suse.de>

PR breakpoints/27313
* break-catch-syscall.c (catch_syscall_split_args): Reject negative
syscall numbers.

gdb/testsuite/ChangeLog:

2021-02-05  Tom de Vries  <tdevries@suse.de>

PR breakpoints/27313
* gdb.base/catch-syscall.exp: Check that "catch syscall -1" is
rejected.

gdb/ChangeLog
gdb/break-catch-syscall.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/catch-syscall.exp

index c6ad0bb8a5353ec271fa3c3b95cc24be8cddf965..e4a5ed887826acdb4cdedb24f86a554c8cc3b6dc 100644 (file)
@@ -1,3 +1,9 @@
+2021-02-05  Tom de Vries  <tdevries@suse.de>
+
+       PR breakpoints/27313
+       * break-catch-syscall.c (catch_syscall_split_args): Reject negative
+       syscall numbers.
+
 2021-02-05  Tom Tromey  <tom@tromey.com>
 
        * compile/compile-c-support.c (get_compile_context)
index 9772ac01497f0563a8cf168afc68c20dd983ea1a..7335377f8992e0f432265b12b8ed0806bd815366 100644 (file)
@@ -390,6 +390,8 @@ catch_syscall_split_args (const char *arg)
       syscall_number = (int) strtol (cur_name, &endptr, 0);
       if (*endptr == '\0')
        {
+         if (syscall_number < 0)
+           error (_("Unknown syscall number '%d'."), syscall_number);
          get_syscall_by_number (gdbarch, syscall_number, &s);
          result.push_back (s.number);
        }
index 84f064730d348b931611da61ce7c381cf6e244b6..5875843472c3fc98d2257fc0c767a22e2fa79e58 100644 (file)
@@ -1,3 +1,9 @@
+2021-02-05  Tom de Vries  <tdevries@suse.de>
+
+       PR breakpoints/27313
+       * gdb.base/catch-syscall.exp: Check that "catch syscall -1" is
+       rejected.
+
 2021-02-05  Tom de Vries  <tdevries@suse.de>
 
        * gdb.dwarf2/main-subprogram.exp: Add KFAIL for PR symtab/24549.
index b45cb8281339ae2b44def55b39e8a4752546b0bd..a92730c05e6c3dca71a4c082fc3f6fc9db0a47b6 100644 (file)
@@ -54,6 +54,9 @@ gdb_test_multiple "continue" $test {
     }
 }
 
+# Test-case for PR27313.  Verify that negative syscall numbers are refused.
+gdb_test "catch syscall -1" "Unknown syscall number '-1'\\."
+
 # All (but the last) syscalls from the example code.  It is filled in
 # proc setup_all_syscalls.
 set all_syscalls { }