From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id s/tqCMoJGWAnJAAAWB0awg (envelope-from ) for ; Tue, 02 Feb 2021 03:14:02 -0500 Received: by simark.ca (Postfix, from userid 112) id 102D51EF80; Tue, 2 Feb 2021 03:14:02 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5E9A71E939 for ; Tue, 2 Feb 2021 03:13:57 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 04CD7396E844; Tue, 2 Feb 2021 08:13:57 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id D77F4396E83E for ; Tue, 2 Feb 2021 08:13:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D77F4396E83E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 007BBAD57 for ; Tue, 2 Feb 2021 08:13:53 +0000 (UTC) Date: Tue, 2 Feb 2021 09:13:52 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH][gdb/breakpoints] Fix segfault for catch syscall -1 Message-ID: <20210202081351.GA28768@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "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 PR breakpoints/27313 * break-catch-syscall.c (catch_syscall_split_args): Reject negative syscall numbers. gdb/testsuite/ChangeLog: 2021-02-02 Tom de Vries 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 { }