diff options
author | Mark Wielaard <mjw@redhat.com> | 2015-12-02 16:44:42 +0100 |
---|---|---|
committer | Mark Wielaard <mjw@redhat.com> | 2015-12-02 16:44:42 +0100 |
commit | 6cebeacaf7184029729a64d8be79b5de5f62b0dc (patch) | |
tree | 4f93996da2b15862ad06e297a490595896a27948 | |
parent | 7adaafa0d71dedd34642bced79e63ebb807634f4 (diff) | |
download | elfutils-6cebeacaf7184029729a64d8be79b5de5f62b0dc.tar.gz |
nm: Don't leak duplicate Dwarf local names.
Badly formed DWARF can have duplicate local names. In which case we do
want to detect those so we don't leak the memory.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
-rw-r--r-- | src/ChangeLog | 4 | ||||
-rw-r--r-- | src/nm.c | 15 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index be7768f6..ffc1b294 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2015-12-02 Mark Wielaard <mjw@redhat.com> + * nm.c (get_local_names): Check for duplicates in local_root tree. + +2015-12-02 Mark Wielaard <mjw@redhat.com> + * unstrip.c (struct data_list): New. (new_data_list): Likewise. (record_new_data): Likewise. @@ -708,11 +708,16 @@ get_local_names (Dwarf *dbg) newp->lowpc = lowpc; newp->highpc = highpc; - /* Since we cannot deallocate individual memory we do not test - for duplicates in the tree. This should not happen anyway. */ - if (tsearch (newp, &local_root, local_compare) == NULL) - error (EXIT_FAILURE, errno, - gettext ("cannot create search tree")); + /* Check whether a similar local_name is already in the + cache. That should not happen. But if it does, we + don't want to leak memory. */ + struct local_name **tres = tsearch (newp, &local_root, + local_compare); + if (tres == NULL) + error (EXIT_FAILURE, errno, + gettext ("cannot create search tree")); + else if (*tres != newp) + free (newp); } while (dwarf_siblingof (die, die) == 0); } |