From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2cIrER4N8WQb9Q4AWB0awg (envelope-from ) for ; Thu, 31 Aug 2023 17:58:54 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=QqxHCRNs; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3CD101E0C2; Thu, 31 Aug 2023 17:58:54 -0400 (EDT) Received: from server2.sourceware.org (ip-8-43-85-97.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 2BC681E028 for ; Thu, 31 Aug 2023 17:58:52 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70F763858413 for ; Thu, 31 Aug 2023 21:58:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70F763858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693519131; bh=PK0J9ExIQK7VTwc0NuIXu1TJXK4Z8B0sWJPCGgFfR0c=; h=Date:To:Cc:Subject:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=QqxHCRNsU48ygnT1V6oNqYm2w5O/AVmtcPEZYNqrMluOVTLoSdIOicUncFVbWRN9f C3DK2xNtkjhob3n+ja5B6P6sc5andJ9Q/pukArJeCLU7KZUk7ZZMZHLLkrj+7Tbc17 HOwvueSKHMTrSMOT3wpe4RBk1Xvoep6Lup3DZeGM= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3BDBA3858D20 for ; Thu, 31 Aug 2023 21:58:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3BDBA3858D20 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-374-KU7MusJENVmU1ojgEOoEcw-1; Thu, 31 Aug 2023 17:58:29 -0400 X-MC-Unique: KU7MusJENVmU1ojgEOoEcw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0541E858EED; Thu, 31 Aug 2023 21:58:29 +0000 (UTC) Received: from f37-zws-nv (unknown [10.22.16.35]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B5A412166B25; Thu, 31 Aug 2023 21:58:28 +0000 (UTC) Date: Thu, 31 Aug 2023 14:58:27 -0700 To: Ciaran Woodward Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] gdb/riscv: Fix oob memory access when printing info registers Message-ID: <20230831145827.422ac366@f37-zws-nv> In-Reply-To: <20230831112449.3822-1-ciaranwoodward@xmos.com> References: <20230831112449.3822-1-ciaranwoodward@xmos.com> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , From: Kevin Buettner via Gdb-patches Reply-To: Kevin Buettner Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On Thu, 31 Aug 2023 12:24:49 +0100 Ciaran Woodward wrote: > If the length of a register name was greater than 15, > print_spaces was called with a negative number, which > prints random data from the heap instead of the requested > number of spaces. > > This could happen if a target-description file was used > to specify additional long-named registers. > > Fix is simple - don't ask for fewer than 1 space (since > we still want column separation). > --- > gdb/riscv-tdep.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c > index ae18eb64452..0bae952156e 100644 > --- a/gdb/riscv-tdep.c > +++ b/gdb/riscv-tdep.c > @@ -1145,7 +1145,7 @@ riscv_print_one_register_info (struct gdbarch *gdbarch, > enum tab_stops { value_column_1 = 15 }; > > gdb_puts (name, file); > - print_spaces (value_column_1 - strlen (name), file); > + print_spaces ( std::max(1, value_column_1 - strlen (name)), file); One small nit: the GDB coding standard requires a space between the 'std::max' and the left paren. With that fixed, it's approved... Approved-by: Kevin Buettner