Message ID | 20230831112449.3822-1-ciaranwoodward@xmos.com |
---|---|
State | Superseded |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 279E83858C78 for <patchwork@sourceware.org>; Thu, 31 Aug 2023 11:26:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2108.outbound.protection.outlook.com [40.107.13.108]) by sourceware.org (Postfix) with ESMTPS id 62597385783F for <gdb-patches@sourceware.org>; Thu, 31 Aug 2023 11:25:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62597385783F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=xmos.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xmos.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oOIGL3d5c/f3ZBCuLKIj2eVc9oniW/2EIIbLDuyKCnsfnx7jgThm+t2ome/ayPPIzWNz2MShVroM5H8//krbffqKK91UDCAnQrae64J8kVBT+eGZKLFMiiDRWDhYQr1IaMUupJ+hhzqDP4w1CWDI1SP8LFC47aCwxBo+MMvQgrV8O1yLgTn1Q4YaN1f6VpBIjhYiDdsuO74rbtsoz/atjHGhNrEOmsEEIihZF2+x1F0d03M9b59hBKqVyMApTvZvi/lDTeKaJcOixN3zKPIsFdDXvXmHvxw3kO2NRagz9+vvC+2iV+pmnLbbzK43qBDjSSypyDuISi2jqb1F0XseJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jpcTLclg/Od/CKQ741OHjdvH69WtOvmH/SrE4LfYF04=; b=i62kMX2s7f8s4SuUDgU1u4GjwbEpRokatOaSE3lt9/QNcA0u/1KSEPJIDV/D74hwx8oEBHpAhDcXyQ/0muEj17l3W+EZNmoT/VovbfSa5o9h817WgHYXidxCf35u7/FWAjr4+Id45DIEVNOA5kfKmtuGSEKuhUkwLvRG5lR9iNyObEBUERZl9MRe1eMLOkSxlWCK/k3kR5TtNHZuFFtq8+q79EQQZjivG9uNLhirpyaD5Y2DLs7jNESr0wqrPzHehbnpf7iYrpQDtHDjfE5EJv0QMxLSLOAtJ8hdMYGZMFCrcnsP4rUIzntz1w112LkNvFoExWuNLTcXpMokwnX6fw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=xmos.com; dmarc=pass action=none header.from=xmos.com; dkim=pass header.d=xmos.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xmos1.onmicrosoft.com; s=selector2-xmos1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jpcTLclg/Od/CKQ741OHjdvH69WtOvmH/SrE4LfYF04=; b=Wvcz21LZcTz/es61MAVUqnuiGSVZhmyaR3WfQbpGR20Y9sPuMJ+/8ejZuQZ9NwHValZuxVZOeNokUn7QQpTylupb5D97Szc3K9Xk+f64bej7EKDa4QrpB4c0/9hBApsGBg4WC2VuIOdbDHO90ZjQ375BXunub8ABpuFHNDcG2Ns= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=xmos.com; Received: from PAXPR09MB5583.eurprd09.prod.outlook.com (2603:10a6:102:280::6) by DB9PR09MB5961.eurprd09.prod.outlook.com (2603:10a6:10:3c7::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20; Thu, 31 Aug 2023 11:25:06 +0000 Received: from PAXPR09MB5583.eurprd09.prod.outlook.com ([fe80::e0e8:7766:49eb:d856]) by PAXPR09MB5583.eurprd09.prod.outlook.com ([fe80::e0e8:7766:49eb:d856%4]) with mapi id 15.20.6745.021; Thu, 31 Aug 2023 11:25:06 +0000 From: Ciaran Woodward <ciaranwoodward@xmos.com> To: gdb-patches@sourceware.org Subject: [PATCH] gdb/riscv: Fix oob memory access when printing info registers Date: Thu, 31 Aug 2023 12:24:49 +0100 Message-Id: <20230831112449.3822-1-ciaranwoodward@xmos.com> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P265CA0098.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2bc::15) To PAXPR09MB5583.eurprd09.prod.outlook.com (2603:10a6:102:280::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR09MB5583:EE_|DB9PR09MB5961:EE_ X-MS-Office365-Filtering-Correlation-Id: 4fec9eb6-746e-4365-fad8-08dbaa14ed3c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: koV+HMwUoiMd/VROUwqKtp9U5WVMAaken6LD7CBRdbBQzv8CtCMA0o7fqF4m1RtzMTqmn+oSROTMN+5CLPrjqxo8N4a/KK8s6bfFfb/e8FYjX+wQF/DFUf47NGXTnoGLGwH2CTJRVvXuZIHvw8ZWT9qsIoabkIZ5U2ulkzXMhiyml1Bu4CAULleNcQ4yFrI7eZEOTVJyzjxDMXjv0BwqzsQIJJ1emYGXTnNM1U2J9Fg47QoyU3E7O8YvBihyq7FiAOblyiD3Pt0hEeyiObo11m2ZXRzRInBNZZjJI32BjM2EXMVb3dZze3IRYh0WxwJXrChblMPzZ2DC3ymBTm7sFJP63OTe3pYKUIT1uSIqBGeRwQ42OhlOogSOx8yLEPYhpOEAGJ5/n0s4dqsRU/svzNBJpnBHcoiqDuvK1qinuX75RslU+Kou7IdVdSusOks+W2hzwp/7yV/1InePAor6vTGbgU+gpuQBa76Bw5FnWSXY/XrWdpZh9uNkrEnjCdjE3lnUprch+aCQdagxvwm0pApe/4rkMKAEiF19PEA1cztOkk3+gRXKetHHTHolbVMyzlRhECt5QbPLelHd1bDt8WcGVf2A4QPbnZDy+Wu9toUpzm7PVWdnrgEMsAD+402z X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR09MB5583.eurprd09.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(346002)(39840400004)(396003)(366004)(136003)(376002)(186009)(451199024)(1800799009)(107886003)(36756003)(4326008)(83380400001)(41300700001)(86362001)(5660300002)(8676002)(8936002)(52116002)(26005)(6486002)(6666004)(6506007)(1076003)(6512007)(2616005)(4744005)(478600001)(38350700002)(38100700002)(66556008)(2906002)(66476007)(66946007)(6916009)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I45ci4BbwRG6kTjJ41xpV6jAxFXr5Airp0rLycuTvqf2mzyF1H6cpiX2H+pdZsj2th56qLbxptWMh/HSglps1D8X9qigaaYUsEQHSBnNlGOPyp4eAkuB9ZkWiGFhRk03k02hy9xhecDhLlrJUqk3Yhs4E2Ky3REE93ijgf/H827KXuaZ3gKh9n8wMtS3xeL9WDZjBDA3mBqCm4CYrX8pDIpRkrMIad+uDinSDKpOcPcFr765nGLtsqtlW+KGbBmSRAd+TzsTEZZld+f1jqG3SHlvqNq5qBp6EOfM8np0v4OVetaFUneVbWpWB1OXi/ztRrq7RgB6bIDJqZapwIelthytQCRITjPVe9RnC6BoYxu1UivoCQtYxDvJToP+Vfda1fNEIHxDYYz8rOlX/YXr5+W4iEuRDf99Te+/YLWn2vKRzUsHnZBFbbPIBx221q2Z7URNH5S94b6uBeCqiWm9RjjwsWFc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9LZ2fkip7edy29qH9aewNoRfU5wb+3ECkCB7qNXHnvcA99ShooSfz13KZzgeUC0lbw== X-OriginatorOrg: xmos.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fec9eb6-746e-4365-fad8-08dbaa14ed3c X-MS-Exchange-CrossTenant-AuthSource: PAXPR09MB5583.eurprd09.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2023 11:25:06.0978 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 975ecfb1-4080-42d2-a01d-4a4d0707a539 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Cd2TXVZjG1q9tTW2dJw5fvAYp1IZ1p0y0wmAl9MBbg4yHgf+aMaLpeEvP6PAR3XH1Z+TqDjv+g8uW4tIEmeJSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR09MB5961 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, 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 <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
gdb/riscv: Fix oob memory access when printing info registers
|
|
Checks
Context | Check | Description |
---|---|---|
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 | success | Testing passed |
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 | success | Testing passed |
linaro-tcwg-bot/tcwg_gdb_build--master-arm | success | Testing passed |
linaro-tcwg-bot/tcwg_gdb_check--master-arm | fail | Patch failed to apply |
Commit Message
Ciaran Woodward
Aug. 31, 2023, 11:24 a.m. UTC
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(-)
Comments
On Thu, 31 Aug 2023 12:24:49 +0100 Ciaran Woodward <ciaranwoodward@xmos.com> 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<int>(1, value_column_1 - strlen (name)), file); One small nit: the GDB coding standard requires a space between the 'std::max<int>' and the left paren. With that fixed, it's approved... Approved-by: Kevin Buettner <kevinb@redhat.com>
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<int>(1, value_column_1 - strlen (name)), file); try {