On Mon, Jan 26, 2015 at 04:54:34PM +0100, Mark Wielaard wrote:
> I guess it should be an error for first_global to be out of
range, or at
> least clamp it to at most syments.
And we do that in find_symtab when we find the normal symtab or the aux
symtab. But in this case after we found the symtab we detect something
is fishy with the string table/shdrs, so we discard the result and fall
back to find_dynsym to get a backup symbol table through phdrs. Which
succeeds. dynsym only has global syms, so we don't need to set
first_global because it is initialized to zero. But... we forgot to
clear the original first_global we found when we discarded the result...
oops.
How does the following fix look?
I assume people thought it looked fine and pushed it to master.
From 6e576f095e6f3bb810e6388ed8e606eacb318b67 Mon Sep 17 00:00:00
2001
From: Mark Wielaard <mjw(a)redhat.com>
Date: Mon, 26 Jan 2015 16:34:57 +0100
Subject: [PATCH] libdwfl: Clear symtab result on error before using
find_dynsym fallback.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
find_dynsym could succeed after find_symtab failed but had already set up
symdata, syments and first_global. find_dynsym would not set or clear
first_global since all syms in dynsym are global. Causing lots of failing
lookups when calling __libdwfl_addrsym if first_global was some huge
bogus value.
Reported-by: Hanno Böck <hanno(a)hboeck.de>
Signed-off-by: Mark Wielaard <mjw(a)redhat.com>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/dwfl_module_getdwarf.c | 3 +++
2 files changed, 8 insertions(+)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 5a97578..d40dbae 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-26 Mark Wielaard <mjw(a)redhat.com>
+
+ * dwfl_module_getdwarf.c (find_symtab): Explicitly clear symdata,
+ syments and first_global on elferr before calling find_dynsym.
+
2014-12-27 Mark Wielaard <mjw(a)redhat.com>
* dwfl_module_getsrc.c (dwfl_module_getsrc): Never match a line that
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 494407d..a31898a 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -1083,6 +1083,9 @@ find_symtab (Dwfl_Module *mod)
if (elf_strptr (mod->symfile->elf, strshndx, 0) == NULL)
{
elferr:
+ mod->symdata = NULL;
+ mod->syments = 0;
+ mod->first_global = 0;
mod->symerr = DWFL_E (LIBELF, elf_errno ());
goto aux_cleanup; /* This cleans up some more and tries find_dynsym. */
}
--
1.8.3.1