Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1
Date: Tue, 2 Feb 2021 09:13:52 +0100	[thread overview]
Message-ID: <20210202081351.GA28768@delia> (raw)

Hi,

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.

Any comments?

Thanks,
- Tom

[gdb/breakpoints] Fix segfault for catch syscall -1

gdb/ChangeLog:

2021-02-02  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-02  Tom de Vries  <tdevries@suse.de>

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

---
 gdb/break-catch-syscall.c                | 2 ++
 gdb/testsuite/gdb.base/catch-syscall.exp | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 9772ac01497..7335377f899 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -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);
 	}
diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
index b45cb828133..a92730c05e6 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.exp
+++ b/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -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 { }

             reply	other threads:[~2021-02-02  8:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02  8:13 Tom de Vries [this message]
2021-02-05 15:52 ` Tom Tromey
2021-02-05 16:27   ` Tom de Vries

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=20210202081351.GA28768@delia \
    --to=tdevries@suse.de \
    --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