From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103539 invoked by alias); 26 Mar 2019 18:46:30 -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 103394 invoked by uid 89); 26 Mar 2019 18:46:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.5 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Mar 2019 18:46:19 +0000 Received: from [172.16.0.89] (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id B71A71E4F4; Tue, 26 Mar 2019 14:46:16 -0400 (EDT) Subject: Re: [RFAv2] Fix buffer overflow regression due to minsym malloc-ed instead of obstack-ed. To: Philippe Waroquiers , Tom Tromey Cc: gdb-patches@sourceware.org References: <20190324091856.2529-1-philippe.waroquiers@skynet.be> <87h8brj7ie.fsf@tromey.com> <1553543645.1504.7.camel@skynet.be> From: Simon Marchi Message-ID: <69c0a306-5829-54c4-d2a6-1b29be829100@simark.ca> Date: Tue, 26 Mar 2019 18:46:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <1553543645.1504.7.camel@skynet.be> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SW-Source: 2019-03/txt/msg00605.txt.bz2 On 2019-03-25 3:54 p.m., Philippe Waroquiers wrote: > On Mon, 2019-03-25 at 09:31 -0600, Tom Tromey wrote: >> Philippe> + int n_after_msymbol = minsym.objfile->per_bfd->minimal_symbol_count >> Philippe> + - (msymbol - minsym.objfile->per_bfd->msymbols.get ()) >> Philippe> + - 1; >> >> What do you think of the appended instead? >> The idea is to make the last element more explicit. > Yes, that looks better, 2 minor comments below. I just wanted to mention that I just hit this bug, and that Tom's patch fixes it for me. >> @@ -1499,21 +1498,24 @@ minimal_symbol_upper_bound (struct bound_minimal_symbol minsym) >> other sections, to find the next symbol in this section with a >> different address. */ >> >> + struct minimal_symbol *last >> + = (minsym.objfile->per_bfd->msymbols.get () >> + + minsym.objfile->per_bfd->minimal_symbol_count); > Are the parenthesis needed here ? It is mentioned here, search for "extra paren": https://www.gnu.org/prep/standards/html_node/Formatting.html#Formatting It's just there to please people who use Emacs :). > Also, I find the name 'last' a little bit confusing, > as in the loop below, last is not handled. > Maybe last could be the 'real' last i.e. as: > minsym.objfile->per_bfd->msymbols.get () +        > + minsym.objfile->per_bfd->minimal_symbol_count - 1; > > and have the '< last' conditions below then be '<= last'. > > That makes more clear for me that we handle the last > element of the array. This, or name the variable "past_the_end" or something like that. Simon