From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 13D8E385780C for ; Fri, 29 Apr 2022 10:18:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13D8E385780C Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-300-5uMoNxrZP-qPyGvKqycMVQ-1; Fri, 29 Apr 2022 06:18:16 -0400 X-MC-Unique: 5uMoNxrZP-qPyGvKqycMVQ-1 Received: by mail-wr1-f71.google.com with SMTP id n17-20020adfc611000000b0020a7e397ccaso2872453wrg.23 for ; Fri, 29 Apr 2022 03:18:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:in-reply-to:references:date :message-id:mime-version; bh=S4sfG0wnqfGi9Bj4oE6e3LVUtawd6h35lwN3KSy83Ek=; b=OXzAfqvvoCnS6DlkE8y9xXCcko1Bj1yfOiD5u4FJm8wavWL7R3zREp8RhOtezOZS+p BZttHC+HX0po8qVdPEeAWuVl4BXUvyL93To4hEq2S2RGmqabCdT0Uyz0xF3QFlcn9I+s I4SJMCfgwF700IpibgpzGfhBX+vLl/CtjflFcoKsAAsH5baONLOjJ2Rhw035RHFcDzzS DKZptbL5qoobg4/j0B+v8ZcWoy/D4FxNnHWO+vLbJe2RHA9kbuqlqByrzRI1cz8etjsw XjCpFMPbNNGYMJVCMu7vzyJ6JNPmcXci2JuACTAuooa4H/O1Q0DtaaofFyCB+BwGkflt pl6Q== X-Gm-Message-State: AOAM533rRu0hGgsFFbcWCOA03r1cd6+L/1eeRub59vwKodZfLyKDVvR8 s23KFvjzW2ty6X42HcfDZOXNF/KFr+p9BX0Osm+kGFGvm7vvbSdo1FO0T39rLHJq7Pc5x5CLFm1 XdEAtTYBKSyy4QMeGHGDnwA== X-Received: by 2002:a05:600c:ad2:b0:394:22e1:ebcf with SMTP id c18-20020a05600c0ad200b0039422e1ebcfmr1213996wmr.181.1651227494995; Fri, 29 Apr 2022 03:18:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJmVJBcE2n4tgCMpaip0sWXbOQuB2YriCPEcjSpJj2bBVsNf9IJg+Ae7cdzcz+lFNrYqY68A== X-Received: by 2002:a05:600c:ad2:b0:394:22e1:ebcf with SMTP id c18-20020a05600c0ad200b0039422e1ebcfmr1213980wmr.181.1651227494781; Fri, 29 Apr 2022 03:18:14 -0700 (PDT) Received: from localhost (host81-136-113-48.range81-136.btcentralplus.com. [81.136.113.48]) by smtp.gmail.com with ESMTPSA id u4-20020a5d6da4000000b0020a8c8d3e00sm2140137wrs.73.2022.04.29.03.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 03:18:14 -0700 (PDT) From: Andrew Burgess To: Luis Machado , Tom Tromey , Luis Machado via Gdb-patches Subject: Re: [PATCH] Fix crash with "maintenance print arc" In-Reply-To: <6d4bd7ec-89de-c115-3205-b0d1999b3aab@arm.com> References: <20220427100753.364631-1-luis.machado@arm.com> <87h76dmdp9.fsf@tromey.com> <6d4bd7ec-89de-c115-3205-b0d1999b3aab@arm.com> Date: Fri, 29 Apr 2022 11:18:12 +0100 Message-ID: <87mtg4nqfv.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.4 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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 29 Apr 2022 10:18:19 -0000 Luis Machado via Gdb-patches writes: > On 4/28/22 16:26, Tom Tromey wrote: >>>>>>> "Luis" == Luis Machado via Gdb-patches writes: >> >> Luis> While doing something else, I noticed GDB crashed with >> Luis> "maintenance print arc". >> >> I think the bug here is that this uses add_show_prefix_cmd and not >> add_basic_prefix_cmd. See the appended, which also fixes the crash. > > Ah, you're right. It did look odd why we were feeding maint commands to > code that is supposed to handle show commands. > >> >> Luis> This happens because the code expects to find a "show" string pattern >> Luis> within "maintenance print arc", since "arc" here is a prefix, and skip it. >> Luis> In this case though, it won't find it, and we will have a bad pointer >> Luis> getting dereferenced. >> >> This looks reasonable to me. > > Should we prevent further situations like this by asserting that we > don't have a class_maintenance prefix being registered as a show > prefix? Would this not trigger for all the existing 'maint show ...' commands? Thanks, Andrew > >> >> Tom >> >> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c >> index 98bd1c4bc0a..3edfd466f3b 100644 >> --- a/gdb/arc-tdep.c >> +++ b/gdb/arc-tdep.c >> @@ -2474,11 +2474,11 @@ _initialize_arc_tdep () >> /* Register ARC-specific commands with gdb. */ >> >> /* Add root prefix command for "maintenance print arc" commands. */ >> - add_show_prefix_cmd ("arc", class_maintenance, >> - _("ARC-specific maintenance commands for printing GDB " >> - "internal state."), >> - &maintenance_print_arc_list, >> - 0, &maintenanceprintlist); >> + add_basic_prefix_cmd ("arc", class_maintenance, >> + _("ARC-specific maintenance commands for printing GDB " >> + "internal state."), >> + &maintenance_print_arc_list, >> + 0, &maintenanceprintlist); >> >> add_cmd ("arc-instruction", class_maintenance, >> dump_arc_instruction_command,