public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Delete temporary string within demangler even in failure cases.
@ 2014-05-27 10:57 Andrew Burgess
  2014-05-27 13:47 ` Ian Lance Taylor
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Burgess @ 2014-05-27 10:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: gdb-patches, Andrew Burgess

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(-)

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')
 	      {
-- 
1.8.1.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Delete temporary string within demangler even in failure cases.
  2014-05-27 10:57 [PATCH] Delete temporary string within demangler even in failure cases Andrew Burgess
@ 2014-05-27 13:47 ` Ian Lance Taylor
  2014-06-10 18:08   ` Andrew Burgess
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Lance Taylor @ 2014-05-27 13:47 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gcc-patches, gdb-patches

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Delete temporary string within demangler even in failure cases.
  2014-05-27 13:47 ` Ian Lance Taylor
@ 2014-06-10 18:08   ` Andrew Burgess
  2014-06-11 11:02     ` Pedro Alves
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Burgess @ 2014-06-10 18:08 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, gdb-patches

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Delete temporary string within demangler even in failure cases.
  2014-06-10 18:08   ` Andrew Burgess
@ 2014-06-11 11:02     ` Pedro Alves
  0 siblings, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2014-06-11 11:02 UTC (permalink / raw)
  To: Andrew Burgess, Ian Lance Taylor; +Cc: gcc-patches, gdb-patches

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,
-- 
Pedro Alves

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-06-11 11:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-27 10:57 [PATCH] Delete temporary string within demangler even in failure cases Andrew Burgess
2014-05-27 13:47 ` Ian Lance Taylor
2014-06-10 18:08   ` Andrew Burgess
2014-06-11 11:02     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).