From patchwork Wed May 29 14:43:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 32896 Received: (qmail 19616 invoked by alias); 29 May 2019 14:43:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 19374 invoked by uid 89); 29 May 2019 14:43:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 May 2019 14:43:55 +0000 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0D0D30044C9; Wed, 29 May 2019 14:43:53 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E10D272BB; Wed, 29 May 2019 14:43:51 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Tom Tromey , Sergio Durigan Junior Subject: [PATCH] Don't crash is dwarf_decode_macro_bytes's 'body' is NULL, even when '!is_define' Date: Wed, 29 May 2019 10:43:43 -0400 Message-Id: <20190529144343.20201-1-sergiodj@redhat.com> In-Reply-To: <87tvdv3jjy.fsf@redhat.com> References: <87tvdv3jjy.fsf@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1715008 On commit 7bede82892a06e6c26989803e70f53697392dcf9 ("Don't crash if dwarf_decode_macro_bytes's 'body' is NULL"), I was too strict when checking if 'body' is NULL: the check only comprised the case when 'is_define' is true. However, the corruption of .debug_macro by rpmbuild's "debugedit" also affects the case when 'is_define' is false, i.e., when the macro is being undefined. This commit improves the check and covers both cases now. This has been tested on Fedora 30 with a problematic debuginfo, and I don't see a segfault anymore. OK to push? gdb/ChangeLog: 2019-05-29 Sergio Durigan Junior Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1715008 * dwarf2read.c (dwarf_decode_macro_bytes): Move check to see if 'body' is NULL to the outter 'if', protecting the '!is_define' situation as well. --- gdb/ChangeLog | 8 ++++++++ gdb/dwarf2read.c | 31 ++++++++++++++----------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f122f5b21f..48e5847b13 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2019-05-29 Sergio Durigan Junior + + Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 + Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1715008 + * dwarf2read.c (dwarf_decode_macro_bytes): Move check to see if + 'body' is NULL to the outter 'if', protecting the '!is_define' + situation as well. + 2019-05-28 Tom Tromey * ada-lang.c (ada_remove_Xbn_suffix) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index f48b931a3f..d1c7a8e67c 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -24635,25 +24635,22 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu, is_define ? _("definition") : _("undefinition"), line == 0 ? _("zero") : _("non-zero"), line, body); - if (is_define) + if (body == NULL) { - if (body != NULL) - parse_macro_definition (current_file, line, body); - else - { - /* Fedora's rpm-build's "debugedit" binary - corrupted .debug_macro sections. - - For more info, see - https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */ - complaint (_("debug info gives %s invalid macro definition " - "without body (corrupted?) at line %d" - "on file %s"), - at_commandline ? _("command-line") - : _("in-file"), - line, current_file->filename); - } + /* Fedora's rpm-build's "debugedit" binary + corrupted .debug_macro sections. + + For more info, see + https://bugzilla.redhat.com/show_bug.cgi?id=1708786 */ + complaint (_("debug info gives %s invalid macro %s " + "without body (corrupted?) at line %d " + "on file %s"), + at_commandline ? _("command-line") : _("in-file"), + is_define ? _("definition") : _("undefinition"), + line, current_file->filename); } + else if (is_define) + parse_macro_definition (current_file, line, body); else { gdb_assert (macinfo_type == DW_MACRO_undef