From patchwork Tue May 14 20:54:58 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: 32689 Received: (qmail 28087 invoked by alias); 14 May 2019 20:55:09 -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 27999 invoked by uid 89); 14 May 2019 20:55:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.9 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=rpm, RPM, HX-Languages-Length:2690 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; Tue, 14 May 2019 20:55:07 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F336C05D3FA for ; Tue, 14 May 2019 20:55:06 +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 E289B608AB; Tue, 14 May 2019 20:55:02 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Sergio Durigan Junior Subject: [PATCH] Don't crash if dwarf_decode_macro_bytes's 'body' is NULL Date: Tue, 14 May 2019 16:54:58 -0400 Message-Id: <20190514205458.28796-1-sergiodj@redhat.com> In-Reply-To: <871s124foc.fsf@tromey.com> References: <871s124foc.fsf@tromey.com> X-IsSubscribed: yes Hi, Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 During the Fedora RPM build process, gdb-add-index is invoked to extract the DWARF index from the binary, and GDB will segfault because dwarf2read.c:parse_definition_macro's 'body' variable is NULL. The underlying problem is that Fedora's rpm-build's "debugedit" program will silently corrupt .debug_macro strings when a binary is compiled with -g3. This is being taken care of by Mark Wielaard, here: https://bugzilla.redhat.com/show_bug.cgi?id=1708786 However, I still feel it's important to make GDB more resilient against invalid DWARF input, so I'm proposing this rather simple patch to catch the situation when "body == NULL" (i.e., it's probably been corrupted) and issue a complaint. This is not a real fix to the problem, of course, but at least GDB is able to finish without segfaulting. OK for master? gdb/ChangeLog: 2019-05-14 Sergio Durigan Junior Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 * dwarf2read.c (dwarf_decode_macro_bytes): Check whether 'body' is NULL, and complain if that's the case. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2read.c | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 19458ccc72..d64ed7df04 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-05-14 Sergio Durigan Junior + + Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 + * dwarf2read.c (parse_macro_definition): Check whether 'body' is + NULL, and complain/return if that's the case. + 2019-05-12 Paul Naert * language.c (language_sniff_from_mangled_name): Fix "langauge" diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b29c089606..63622ba76f 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -24609,7 +24609,23 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu, line == 0 ? _("zero") : _("non-zero"), line, body); if (is_define) - parse_macro_definition (current_file, line, body); + { + 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"), + at_commandline ? _("command-line") + : _("in-file"), + line == 0 ? _("zero") : _("non-zero"), line); + } + } else { gdb_assert (macinfo_type == DW_MACRO_undef