* [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1
@ 2021-02-02 8:13 Tom de Vries
2021-02-05 15:52 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2021-02-02 8:13 UTC (permalink / raw)
To: gdb-patches
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 { }
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1
2021-02-02 8:13 [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1 Tom de Vries
@ 2021-02-05 15:52 ` Tom Tromey
2021-02-05 16:27 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2021-02-05 15:52 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> PR breakpoints/27313
Tom> * break-catch-syscall.c (catch_syscall_split_args): Reject negative
Tom> syscall numbers.
Looks good.
Thank you for doing this.
Tom> + if (syscall_number < 0)
Tom> + error (_("Unknown syscall number '%d'."), syscall_number);
Does syscall_number==0 make sense?
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1
2021-02-05 15:52 ` Tom Tromey
@ 2021-02-05 16:27 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2021-02-05 16:27 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2/5/21 4:52 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> PR breakpoints/27313
> Tom> * break-catch-syscall.c (catch_syscall_split_args): Reject negative
> Tom> syscall numbers.
>
> Looks good.
> Thank you for doing this.
>
> Tom> + if (syscall_number < 0)
> Tom> + error (_("Unknown syscall number '%d'."), syscall_number);
> > Does syscall_number==0 make sense?
Apparently:
...
(gdb) catch syscall 0
Catchpoint 1 (syscall 'read' [0])
...
Thanks,
- Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-05 16:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02 8:13 [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1 Tom de Vries
2021-02-05 15:52 ` Tom Tromey
2021-02-05 16:27 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).