From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OHoPEQJ1CWjuQAIAWB0awg (envelope-from ) for ; Wed, 23 Apr 2025 19:17:22 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T8eUR1SH; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 41DFD1E0C3; Wed, 23 Apr 2025 19:17:22 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 41E921E05C for ; Wed, 23 Apr 2025 19:17:20 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C1ECB3857839 for ; Wed, 23 Apr 2025 23:17:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C1ECB3857839 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T8eUR1SH Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id EAF663857B94 for ; Wed, 23 Apr 2025 23:15:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EAF663857B94 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EAF663857B94 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745450155; cv=none; b=E8NTs5fnnFlkJf8fnrQwKyMFOeYmOTS3RRQ81xUs6rmks4rXEKrhDw0IAHoUkM0buxpteYuq/jIYWMqbQgW1+p6yk8VZdN3denhpSc+7s1MAfoeLjn8jbTauRpN/B6J2MywmcAIwYM9EXWZWEP4FjK3hZTEgpOyiT7siMfS5wv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745450155; c=relaxed/simple; bh=EgyMu+btedYpZPm0kmZMUzHF1WnJUa5xFG97LTEc/bI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=h9UX0N9msIH4S65Uls9Ek/CGjD7Ea4tTda1xvSkc286fTy0KSbZzi7NA3IAR1bw16hUef31+hI45d8un4EzcbcgbVjZxjLwbO6oQMr7TCGbAZWHx7BRWiqLRhPnwKXFZmmqMv26RaCpnrzP4W6igN4FKtUa50j+HQ68bZ3YagVY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EAF663857B94 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1745450154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P0jOHCT+6l+vmjwVOj88DY64ix2F3eoPAT3ppcDaJDA=; b=T8eUR1SHya7dl9M8rNouIQQKqD18HPWglHFPjN1rLqmLUMN6V5kP8kx0V2U2DjdVwA/9+D N5kr2Ao6uyGBcy83B/vsdO8qqz7Hu6aeIIIO83CyahfbXHh6NUrBsUj2MPveJpcJYpAkV8 +MnSbwwedwxlDaHVqsicWxzmHPJY/8c= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-SmgaQAATORiZoeGVv0e-PA-1; Wed, 23 Apr 2025 19:15:53 -0400 X-MC-Unique: SmgaQAATORiZoeGVv0e-PA-1 X-Mimecast-MFC-AGG-ID: SmgaQAATORiZoeGVv0e-PA_1745450152 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 74F8C18001CA; Wed, 23 Apr 2025 23:15:52 +0000 (UTC) Received: from f41-zbm-amd (unknown [10.22.80.67]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A1482180045C; Wed, 23 Apr 2025 23:15:51 +0000 (UTC) Date: Wed, 23 Apr 2025 16:15:48 -0700 From: Kevin Buettner To: Kirill Radkin Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdbserver: Update require_int function to parse offset for pread packet Message-ID: <20250423161548.03f50c47@f41-zbm-amd> In-Reply-To: <20250421115941.62567-1-kirill.radkin@syntacore.com> References: <20250421115941.62567-1-kirill.radkin@syntacore.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: AC_3ZeIjF-ixWCZEqMON_VqlE2MPhzTi2aGzBGBsnCo_1745450152 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hi Kirill, Just a few nits... On Mon, 21 Apr 2025 14:59:41 +0300 Kirill Radkin wrote: > Currently gdbserver uses require_int() function to parse the requested offset > (in vFile::pread packet and the like). This function allows integers up to > 0x7fffffff (to fit in 32-bit int), however the offset (for pread system call) > has an off_t type which can be larger than 32-bit. > > This patch allows require_int() function to parse offset up to the maximum > value implied by the off_t type. > --- > gdb/testsuite/gdb.server/pread-offset-size.S | 26 +++++++++++ > .../gdb.server/pread-offset-size.exp | 45 +++++++++++++++++++ > gdbserver/hostio.cc | 18 +++++--- > 3 files changed, 84 insertions(+), 5 deletions(-) > create mode 100644 gdb/testsuite/gdb.server/pread-offset-size.S > create mode 100644 gdb/testsuite/gdb.server/pread-offset-size.exp > > diff --git a/gdb/testsuite/gdb.server/pread-offset-size.S b/gdb/testsuite/gdb.server/pread-offset-size.S > new file mode 100644 > index 00000000000..31748090ac3 > --- /dev/null > +++ b/gdb/testsuite/gdb.server/pread-offset-size.S > @@ -0,0 +1,26 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2023-2023 Free Software Foundation, Inc. Please update the second 2023 to 2025. (Do you even need the first 2023?) > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > + .text > + .globl _start > +_start: > + .skip 3742415472 > + ret > + .globl f > + .type f, @function > +f: > + ret > diff --git a/gdb/testsuite/gdb.server/pread-offset-size.exp b/gdb/testsuite/gdb.server/pread-offset-size.exp > new file mode 100644 > index 00000000000..c6acaa382b2 > --- /dev/null > +++ b/gdb/testsuite/gdb.server/pread-offset-size.exp > @@ -0,0 +1,45 @@ > +# Copyright (C) 2023-2023 Free Software Foundation, Inc. Likewise. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +load_lib gdbserver-support.exp > + > +require allow_gdbserver_tests > + > +standard_testfile .S > + > +if { [prepare_for_testing ${testfile}.exp $testfile \ > + $srcfile {debug additional_flags=-nostdlib} ] } { git am complained of a whitespace problem here. Basically, it wants you to use a tab instead of the leading 8 spaces. > + return -1 > +} > + > +gdb_exit > +gdb_start > + > +gdb_test_no_output "set remote exec-file $binfile" \ > +"set remote exec-file" > + > +# Make sure we're disconnected, in case we're testing with an > +# extended-remote board, therefore already connected. > +gdb_test "disconnect" ".*" > + > +set res [gdbserver_spawn ""] > +set gdbserver_protocol [lindex $res 0] > +set gdbserver_gdbport [lindex $res 1] > + > +gdb_test "target $gdbserver_protocol $gdbserver_gdbport" \ > +"Remote debugging using .*" \ > +"target $gdbserver_protocol $gdbserver_gdbport" > + > +gdb_test "break f" "Breakpoint 1.*" > diff --git a/gdbserver/hostio.cc b/gdbserver/hostio.cc > index 17b6179d8ca..2207804670b 100644 > --- a/gdbserver/hostio.cc > +++ b/gdbserver/hostio.cc > @@ -89,12 +89,18 @@ require_filename (char **pp, char *filename) > return 0; > } > > +template > static int > -require_int (char **pp, int *value) > +require_int (char **pp, T *value) > { > + constexpr bool is_signed = std::is_signed::value; > + > char *p; > int count, firstdigit; > > + /* Max count of hexadecimal digits in off_t (1 hex digit is 4 bits) */ Please place a period (.) at the end of the comment and make sure that it's followed by 2 spaces. > + int max_count = sizeof(T) * CHAR_BIT / 4; > + > p = *pp; > *value = 0; > count = 0; > @@ -111,9 +117,9 @@ require_int (char **pp, int *value) > firstdigit = nib; > > /* Don't allow overflow. */ > - if (count >= 8 || (count == 7 && firstdigit >= 0x8)) > + if (count >= max_count > + || (is_signed && count == (max_count - 1) && firstdigit >= 0x8)) > return -1; > - > *value = *value * 16 + nib; > p++; > count++; > @@ -343,7 +349,8 @@ handle_open (char *own_buf) > static void > handle_pread (char *own_buf, int *new_packet_len) > { > - int fd, ret, len, offset, bytes_sent; > + int fd, ret, len, bytes_sent; > + off_t offset; > char *p, *data; > static int max_reply_size = -1; > > @@ -410,7 +417,8 @@ handle_pread (char *own_buf, int *new_packet_len) > static void > handle_pwrite (char *own_buf, int packet_len) > { > - int fd, ret, len, offset; > + int fd, ret, len; > + off_t offset; > char *p, *data; > > p = own_buf + strlen ("vFile:pwrite:"); > -- > 2.43.0 > >