From: Mark Wielaard Date: Wed, 2 Dec 2015 15:44:42 +0000 (+0100) Subject: nm: Don't leak duplicate Dwarf local names. X-Git-Tag: elfutils-0.165~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fbd857267a6bffc57225857690aaa383ac58426;p=thirdparty%2Felfutils.git 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index be7768f64..ffc1b294d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2015-12-02 Mark Wielaard + + * nm.c (get_local_names): Check for duplicates in local_root tree. + 2015-12-02 Mark Wielaard * unstrip.c (struct data_list): New. diff --git a/src/nm.c b/src/nm.c index 15d9da4ab..69623fe89 100644 --- a/src/nm.c +++ b/src/nm.c @@ -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); }