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.129.124]) by sourceware.org (Postfix) with ESMTPS id 77AFA3858D39 for ; Fri, 4 Mar 2022 12:36:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 77AFA3858D39 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-Iaw4jKRgOtuwssW-BnqaEA-1; Fri, 04 Mar 2022 07:36:02 -0500 X-MC-Unique: Iaw4jKRgOtuwssW-BnqaEA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69273180A08E; Fri, 4 Mar 2022 12:36:01 +0000 (UTC) Received: from [10.97.116.79] (ovpn-116-79.gru2.redhat.com [10.97.116.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2DC377A534; Fri, 4 Mar 2022 12:35:58 +0000 (UTC) Message-ID: <14de2fb0-8018-6cf4-584f-168310f2c80a@redhat.com> Date: Fri, 4 Mar 2022 09:35:54 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] gdb/solib-svr4.c: Fix segfault caused by NULL pointer To: Mikael Szreder , "gdb-patches@sourceware.org" References: From: Bruno Larsen In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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, 04 Mar 2022 12:36:10 -0000 Hi Mikael Thanks for looking into this. On 3/4/22 07:54, Mikael Szreder via Gdb-patches wrote: > Inside the function 'enable_break' there is a call to 'find_program_interpreter'. > This function returns an empty vector when an ELF file does not contain > an interpreter because the function 'read_program_header' header > returns an empty vector on failure. > > The call to 'interp_name_holder->data()' then returns NULL for an empty vector. > This causes a segmentation fault down the line. I see that interp_name_holder is a gdb::optional type. This makes me wonder, is there a good reason for find_name_program to return an instantiated empty byte_vector, instead of returning a non-instantiated gdb::optional? I could be missing something, but to me it seems to make gdb::optional redundant. I'd also ask that the title be changed to something like "gdb/solib-svr4.c: Fix segfault caused by NULL pointer in function enable_break", as the current name is a bit generic. > --- > gdb/solib-svr4.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c > index 69f2991f5e6..18bd712e061 100644 > --- a/gdb/solib-svr4.c > +++ b/gdb/solib-svr4.c > @@ -2204,7 +2204,7 @@ enable_break (struct svr4_info *info, int from_tty) > into the old breakpoint at symbol code. */ > gdb::optional interp_name_holder > = find_program_interpreter (); > - if (interp_name_holder) > + if (interp_name_holder && interp_name_holder->size() != 0) > { > const char *interp_name = (const char *) interp_name_holder->data (); > CORE_ADDR load_addr = 0; -- Cheers! Bruno Larsen