From patchwork Fri May 10 21:04:25 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: 32640 Received: (qmail 33122 invoked by alias); 10 May 2019 21:04:33 -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 33114 invoked by uid 89); 10 May 2019 21:04:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-14.8 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=sk:bugzill, Later 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; Fri, 10 May 2019 21:04:31 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84E4E10C6F for ; Fri, 10 May 2019 21:04:30 +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 05C3C5D70D; Fri, 10 May 2019 21:04:27 +0000 (UTC) From: Sergio Durigan Junior To: GDB Patches Cc: Sergio Durigan Junior Subject: [PATCH] Don't crash if parse_definition_macro's 'body' is NULL Date: Fri, 10 May 2019 17:04:25 -0400 Message-Id: <20190510210425.2750-1-sergiodj@redhat.com> X-IsSubscribed: yes Hi, Ref.: https://bugzilla.redhat.com/show_bug.cgi?id=1708192 https://bugzilla.redhat.com/show_bug.cgi?id=1708786 Fedora's rpm-build's "debugedit" program will silently corrupt .debug_macro strings when a binary is compiled with -g3. Later in the build phase, 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. This very simple patch is just a safeguard against this scenario; it is not a fix for the problem (which actually happens on "debugedit", and which Mark Wielaard is already working on), but at least it makes GDB not crash on invalid DWARF, which is a plus IMO. OK for master? gdb/ChangeLog: 2019-05-10 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. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2read.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4da409633a..53a4721cb3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-05-10 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-10 Simon Marchi * contrib/cc-with-tweaks.sh: Validate dwz's work. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b29c089606..e270e7cef3 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -24161,6 +24161,13 @@ parse_macro_definition (struct macro_source_file *file, int line, { const char *p; + if (body == NULL) + { + complaint (_("macro debug info contains a malformed " + "(null) macro definition")); + return; + } + /* The body string takes one of two forms. For object-like macro definitions, it should be: