Message ID | 1401188253-15214-1-git-send-email-aburgess@broadcom.com |
---|---|
State | Committed |
Headers |
Received: (qmail 23244 invoked by alias); 27 May 2014 10:57:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 23220 invoked by uid 89); 27 May 2014 10:57:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-gw1-out.broadcom.com Received: from mail-gw1-out.broadcom.com (HELO mail-gw1-out.broadcom.com) (216.31.210.62) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 May 2014 10:57:47 +0000 Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw1-out.broadcom.com with ESMTP; 27 May 2014 04:03:24 -0700 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Tue, 27 May 2014 03:57:45 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.174.1; Tue, 27 May 2014 03:57:45 -0700 Received: from xl-cam-21.broadcom.com (xl-cam-21.cam.broadcom.com [10.177.132.81]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 278A49F9F7; Tue, 27 May 2014 03:57:45 -0700 (PDT) Received: by xl-cam-21.broadcom.com (Postfix, from userid 15136) id 753252CE899E; Tue, 27 May 2014 11:57:44 +0100 (BST) From: Andrew Burgess <aburgess@broadcom.com> To: <gcc-patches@gcc.gnu.org> CC: <gdb-patches@sourceware.org>, Andrew Burgess <aburgess@broadcom.com> Subject: [PATCH] Delete temporary string within demangler even in failure cases. Date: Tue, 27 May 2014 11:57:33 +0100 Message-ID: <1401188253-15214-1-git-send-email-aburgess@broadcom.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes |
Commit Message
Andrew Burgess
May 27, 2014, 10:57 a.m. UTC
Spotted that a call to demangle_template might allocate storage within a temporary string even if the call to demangle_template eventually returns failure. This will never cause the demangler to crash, but does leak memory, as a result I've not added any tests for this. Calling string_delete is safe, even if nothing is allocated into the string, the string is initialised with string_init, so we know the internal pointers are NULL. I don't have gcc write privilages, so if this is approved could someone please commit for me. Thanks, Andrew libiberty/ChangeLog * cplus-dem.c (do_type): Call string_delete even if the call to demangle_template fails. --- libiberty/cplus-dem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Comments
On Tue, May 27, 2014 at 3:57 AM, Andrew Burgess <aburgess@broadcom.com> wrote: > > libiberty/ChangeLog > > * cplus-dem.c (do_type): Call string_delete even if the call to > demangle_template fails. This is OK. Thanks. I have to ask: you know this code is not used, right? You're looking at the old demangler, for symbols generated by versions of g++ before GCC 3.4 (released 2004). The demangler for current versions of g++ is in cp-demangle.c. Ian
On 27/05/2014 2:47 PM, Ian Lance Taylor wrote: > On Tue, May 27, 2014 at 3:57 AM, Andrew Burgess <aburgess@broadcom.com> wrote: >> >> libiberty/ChangeLog >> >> * cplus-dem.c (do_type): Call string_delete even if the call to >> demangle_template fails. > > This is OK. > > Thanks. > > I have to ask: you know this code is not used, right? You're looking > at the old demangler, for symbols generated by versions of g++ before > GCC 3.4 (released 2004). The demangler for current versions of g++ is > in cp-demangle.c. Sorry for the delay. Yes, I know it's not very old code, but it is still shipped, and consumers such as gdb can still trigger this code path. Thanks for taking a look at this patch for me. I don't have gcc write permissions, would you (or any other interested maintainer) mind committing this for me please. Thanks, Andrew
On 06/10/2014 07:08 PM, Andrew Burgess wrote: > I don't have gcc write permissions, would you (or any other interested > maintainer) mind committing this for me please. Done, and merged to binutils-gdb git repo. Thanks,
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c index e948487..1c713aa 100644 --- a/libiberty/cplus-dem.c +++ b/libiberty/cplus-dem.c @@ -3656,7 +3656,10 @@ do_type (struct work_stuff *work, const char **mangled, string *result) string_delete (&temp); } else - break; + { + string_delete (&temp); + break; + } } else if (**mangled == 'Q') {