From: Andrew Burgess <aburgess@broadcom.com>
To: <gcc-patches@gcc.gnu.org>
Cc: <jason@redhat.com>, <gdb-patches@sourceware.org>,
Andrew Burgess <aburgess@broadcom.com>
Subject: [PATCH] cplus-demangler, free resource after a failed call to gnu_special.
Date: Fri, 09 May 2014 14:35:00 -0000 [thread overview]
Message-ID: <1399646123-9960-1-git-send-email-aburgess@broadcom.com> (raw)
Fixes issue:
https://sourceware.org/bugzilla/show_bug.cgi?id=16817
A call to gnu_special within internal_cplus_demangle could cause memory
resources to be allocated, even if the demangle eventually fails. The
following call into demangle_prefix will then be passed some partially
initialised state.
I've only tested this against the libiberty "make check" and against gdb on
x86-64 linux.
I don't have write access for gcc svn, but Broadcom does have a copyright
assignment in place for gcc, so if this patch is approved, could someone
apply it please.
Thanks,
Andrew
libiberty/ChangeLog
* cplus-dmem.c (internal_cplus_demangle): Free any resources
allocated by possible previous call to gnu_special.
(squangle_mop_up): Reset pointers to NULL after calling free.
* testsuite/demangle-expected: New test case.
---
libiberty/cplus-dem.c | 7 +++++++
libiberty/testsuite/demangle-expected | 5 +++++
2 files changed, 12 insertions(+)
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index e948487..1c41c6f 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -1175,6 +1175,11 @@ internal_cplus_demangle (struct work_stuff *work, const char *mangled)
if ((AUTO_DEMANGLING || GNU_DEMANGLING))
{
success = gnu_special (work, &mangled, &decl);
+ if (!success)
+ {
+ delete_work_stuff (work);
+ string_delete (&decl);
+ }
}
if (!success)
{
@@ -1218,10 +1223,12 @@ squangle_mop_up (struct work_stuff *work)
if (work -> btypevec != NULL)
{
free ((char *) work -> btypevec);
+ work->btypevec = NULL;
}
if (work -> ktypevec != NULL)
{
free ((char *) work -> ktypevec);
+ work->ktypevec = NULL;
}
}
diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected
index 453f9a3..864ee7e 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4343,3 +4343,8 @@ cereal::detail::InputBindingMap<cereal::JSONInputArchive>::Serializers cereal::p
--format=gnu-v3
_ZNSt9_Any_data9_M_accessIPZ4postISt8functionIFvvEEEvOT_EUlvE_EERS5_v
void post<std::function<void ()> >(std::function<void ()>&&)::{lambda()#1}*& std::_Any_data::_M_access<void post<std::function<void ()> >(void post<std::function<void ()> >(std::function<void ()>&&)::{lambda()#1}*&&)::{lambda()#1}*>()
+# https://sourceware.org/bugzilla/show_bug.cgi?id=16817
+--format=auto --no-params
+_QueueNotification_QueueController__$4PPPPPPPM_A_INotice___Z
+_QueueNotification_QueueController__$4PPPPPPPM_A_INotice___Z
+_QueueNotification_QueueController__$4PPPPPPPM_A_INotice___Z
--
1.8.1.3
next reply other threads:[~2014-05-09 14:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-09 14:35 Andrew Burgess [this message]
2014-05-09 20:53 ` Ian Lance Taylor
2014-05-10 19:14 ` Andrew Burgess
2014-05-12 5:40 ` Ian Lance Taylor
2014-05-14 9:01 ` Gary Benson
2014-05-14 9:30 ` Andrew Burgess
2014-05-14 14:20 ` Gary Benson
2014-05-22 11:58 ` Thomas Schwinge
2014-05-22 16:02 ` Gary Benson
2014-05-22 16:13 ` Thomas Schwinge
2014-05-22 19:34 ` Gary Benson
2014-05-28 22:17 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399646123-9960-1-git-send-email-aburgess@broadcom.com \
--to=aburgess@broadcom.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).