From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23031 invoked by alias); 14 May 2019 20:54:41 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 23023 invoked by uid 89); 14 May 2019 20:54:41 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=complaints, at_commandline, is_define, undefinition 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:54:40 +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 C5FF43092648; Tue, 14 May 2019 20:54:38 +0000 (UTC) Received: from localhost (unused-10-15-17-196.yyz.redhat.com [10.15.17.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0428608AB; Tue, 14 May 2019 20:54:38 +0000 (UTC) From: Sergio Durigan Junior To: Tom Tromey Cc: GDB Patches Subject: Re: [PATCH] Don't crash if parse_definition_macro's 'body' is NULL References: <20190510210425.2750-1-sergiodj@redhat.com> <871s124foc.fsf@tromey.com> Date: Tue, 14 May 2019 20:54:00 -0000 In-Reply-To: <871s124foc.fsf@tromey.com> (Tom Tromey's message of "Mon, 13 May 2019 08:01:07 -0600") Message-ID: <8736lg69kh.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2019-05/txt/msg00339.txt.bz2 On Monday, May 13 2019, Tom Tromey wrote: >>>>>> "Sergio" == Sergio Durigan Junior writes: > > Sergio> This very simple patch is just a safeguard against this scenario; it > Sergio> is not a fix for the problem (which actually happens on "debugedit", > Sergio> and which Mark Wielaard is already working on), but at least it makes > Sergio> GDB not crash on invalid DWARF, which is a plus IMO. > > I don't really get why read_direct_string (and the other functions like > it) returns NULL when it sees an empty string. How is something like > "#define X" represented such that this doesn't return NULL? Thanks for the review. We've already talked on IRC, but I'll just mention it here as well: When read_indirect_string_at_offset is called (from dwarf_decode_macro_bytes), you see this code: ... if (sect->buffer[str_offset] == '\0') return NULL; ... You were wondering why a case like "#define X" didn't trigger this bug, because NULL should be returned. However, as I found, in this scenario sect->buffer will contain "X ". I.e., it will always contain the macro's name + its (optional) value. What we're actually dealing with here, in debugedit's case, is the corruption of the .debug_macro section, which renders the define useless. A more in-depth analysis by Keith can be found here: https://bugzilla.redhat.com/show_bug.cgi?id=1684303#c2 > Other complaints in the caller of parse_macro_definition provide a bit > more context, like the macro name, source file, and line number: > > complaint (_("debug info gives %s macro %s with %s line %d: %s"), > at_commandline ? _("command-line") : _("in-file"), > is_define ? _("definition") : _("undefinition"), > line == 0 ? _("zero") : _("non-zero"), line, body); > > ... so maybe the new complaint could as well. I did my best and updated the complaint to contain more info. I'm afraid the only extra bit I was able to add was the line number, which, by my tests, will not be entirely correct (perhaps due to the corruption itself). I'll send the patch soon. Thanks, -- Sergio GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 Please send encrypted e-mail if possible http://sergiodj.net/