From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-114.mimecast.com (us-smtp-delivery-114.mimecast.com [170.10.129.114]) by sourceware.org (Postfix) with ESMTPS id 03FBF3858288 for ; Mon, 19 Dec 2022 11:48:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03FBF3858288 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=labware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=labware.com Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2101.outbound.protection.outlook.com [104.47.58.101]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-To_8iX1rP9ie7PIghgIDfw-1; Mon, 19 Dec 2022 06:48:02 -0500 X-MC-Unique: To_8iX1rP9ie7PIghgIDfw-1 Received: from DM6PR17MB3113.namprd17.prod.outlook.com (2603:10b6:5:6::10) by PH7PR17MB6789.namprd17.prod.outlook.com (2603:10b6:510:248::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Mon, 19 Dec 2022 11:47:57 +0000 Received: from DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::1729:3f69:5d95:b768]) by DM6PR17MB3113.namprd17.prod.outlook.com ([fe80::1729:3f69:5d95:b768%7]) with mapi id 15.20.5924.016; Mon, 19 Dec 2022 11:47:57 +0000 From: Jan Vrany To: gdb-patches@sourceware.org CC: Jan Vrany , Simon Marchi Subject: [pushed] gdb: fix command lookup in execute_command () Date: Mon, 19 Dec 2022 11:47:45 +0000 Message-ID: <20221219114745.455799-1-jan.vrany@labware.com> X-Mailer: git-send-email 2.35.1 X-ClientProxiedBy: LO2P265CA0373.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a3::25) To DM6PR17MB3113.namprd17.prod.outlook.com (2603:10b6:5:6::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR17MB3113:EE_|PH7PR17MB6789:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ea7032f-750f-4096-18c1-08dae1b6df33 X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0 X-Microsoft-Antispam-Message-Info: NIsYriLBzhhKvo0oJpKZG6Djn7u+pcmojsIAx1LXHXaRGCrkJ3LCIzaHitkw+8evku0nCNoTM2bfRwW6tNxEgRWCgTVYRhrWsTL5BMULRVKxjfyyyU7v59k8/vGsnpPebKh+YxWtHGYMDrdnJbDMW+dq3Q4Cwko8E3ddB2557zZ3Zz9pnZUZ2r1QOtkj0rsMg+QfRsk0XJapa0QRvVH6oHicY0XpWl7b/B63ON2ghcR2NUY7noLmKHPTrSp6O2RihpDrOijTyfQly4yyT32PQ5t5ZEbi6gTxZJWVBkWZ790BGKcqoYEWGALKDJWST9kCp1O8xQCQNrZ8RoFE1znkHjChiDi/gfKFjrTlgy/Qk5PLzpeMnAlawFF3e3XSFyAyHeEewWmanXZlI9RSRvm21HAW5dyxCKvrA8lAphbXunmEdNyrt2ujChHqI6psSNW6zGb9Jl/k+iym88C5DL9XncSHtAGSKaP03rlHctst3DmdSbfu/wSpi+KYHDNi1jBMT7PNxz6hxqRVjQIu0LVF1b2cboi2jW38RDsFAg2ZDQ8sIgDtzfI7k7QJXle1oeqYJYoJ2hEZHzhmq2o9mBV0GlR6o+l5i0sT0FFo6f4JlHwCaCikqhSb29k6RNVxQwBu3uzJn3PEWkUriW/wkowVHev3aZycoBl7xUUi3A4wzaY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR17MB3113.namprd17.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(366004)(376002)(136003)(346002)(39850400004)(451199015)(1076003)(36756003)(6486002)(6916009)(54906003)(66556008)(86362001)(6506007)(8676002)(66476007)(4326008)(38100700002)(66946007)(2616005)(478600001)(316002)(83380400001)(8936002)(5660300002)(6666004)(2906002)(41300700001)(84970400001)(186003)(26005)(44832011)(6512007);DIR:OUT;SFP:1101 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0SlU3DwO7FxNsFDy0x69RZKVsL/8E8kzCddVrVijq4ue9goRrW4m44Zwyktw?= =?us-ascii?Q?clcxAWjsbUBE1QCjKGZyt2IhyVT5SdG4Q7n2JL+ka1hKgUC0JAP24qSjh8nM?= =?us-ascii?Q?q2582jy6GxLjabWof8+ZwLsbf2xC5ZMIGVJfFJ4PzmTBCVghRq/BHzw6FHYS?= =?us-ascii?Q?buhJLZM3pGQc1j24sY90eFep/PzdJpWQLeWCeigv+0oabiTSPjm4BPxQfeD3?= =?us-ascii?Q?5swN/iZMxFCOLsVO5D9PwDpdRJtVjuPVFHXsIp1BZzyAuhLEoXc6bfeukavj?= =?us-ascii?Q?vPaDwd9iuEsXYQjN5tgBrzxY96Y96xibpJaM6mxYZ8/8t1lqdY2+iLlfMPtc?= =?us-ascii?Q?AsWDSW1tRix+pEe+piQyRGo9rVIOb/auLOWFRQqt5RXWS4QfLBhm+fMYzW35?= =?us-ascii?Q?9S7HF/vtAVtMbj5G10oz2lsBgFRXbZD1ZsF5l01mN9wtu+x8XtL46sW5ALxs?= =?us-ascii?Q?OG1DiEH6SccsfSyKPR04I5MUX/kNwdNy76GMAe4JgJ/zzD5eToe0behcXfIn?= =?us-ascii?Q?yKJ3DPxnQ7ofld1qHaeXaQZgFXsLlA5VjW52ZB2UIq9fk0rzTNxFS1lG4zJ0?= =?us-ascii?Q?MipUQfL4XNBQ98VrH0q5lPoBfvSg0RuClb18lJhJHFfe0C9m3JKbAdw3Yvli?= =?us-ascii?Q?PkYcgsqgLAr3+sAa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?= =?us-ascii?Q?7wVOsw7igD/0OVzZ1uQRbTO7NLE28YJvhpNPmnRq?= X-OriginatorOrg: labware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ea7032f-750f-4096-18c1-08dae1b6df33 X-MS-Exchange-CrossTenant-AuthSource: DM6PR17MB3113.namprd17.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Dec 2022 11:47:57.4905 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b5db0322-1aa0-4c0a-859c-ad0f96966f4c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: c03iWoc7Mo3YAx5884OS1fd9midI8OIE3JE2BRKRo32vsGUtAtVGggDZZ39zHMmPg97YKtUY+ZdH0RCushzl9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR17MB6789 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: labware.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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 List-Id: Commit b5661ff2 ("gdb: fix possible use-after-free when executing commands") used lookup_cmd_exact () to lookup command again after its execution to avoid possible use-after-free error. However this change broke test gdb.base/define.exp which defines a post-hook for subcommand ("target testsuite"). In this case, lookup_cmd_exact () returned NULL because there's no command 'testsuite' in top-level commands. This commit fixes this case by looking up the command again using the original command line via lookup_cmd (). Approved-By: Simon Marchi --- gdb/top.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gdb/top.c b/gdb/top.c index 45e65beb3b3..b732f29653f 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -651,11 +651,6 @@ execute_command (const char *p, int from_tty) =09 } =09} =20 - /* Remember name of the command. This is needed later when -=09 executing command post-hooks to handle the case when command -=09 is redefined or removed during it's execution. See below. */ - std::string c_name (c->name); - /* If this command has been pre-hooked, run the hook first. */ execute_cmd_pre_hook (c); =20 @@ -698,7 +693,8 @@ execute_command (const char *p, int from_tty) =09 We need to lookup the command again since during its execution, =09 a command may redefine itself. In this case, C pointer =09 becomes invalid so we need to look it up again. */ - c =3D lookup_cmd_exact (c_name.c_str (), cmdlist); + const char *cmd2 =3D cmd_start; + c =3D lookup_cmd (&cmd2, cmdlist, "", nullptr, 1, 1); if (c !=3D nullptr) =09execute_cmd_post_hook (c); =20 --=20 2.35.1