[PATCH] nm: Handle corrupt symbol name table.

2020-06-07 Thread Mark Wielaard
We try to sort symbol by name (when neither -n nor -p are given).
This could crash if the symbol name table was corrupt. Use elf_strptr
to get the symbol name and use the empty string in case a name couldn't
be found.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog |  8 
 src/nm.c  | 15 +--
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 4684d332..512d7b54 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2020-06-07  Mark Wielaard  
+
+   * nm.c (sort_by_name_strtab): Replace by...
+   (sort_by_name_elf): New static Elf pointer and ...
+   (sort_by_name_ndx): New static size_t index.
+   (sort_by_name): Use elf_strptr to get symbol string.
+   (show_symbols): Set sort_by_name_elf and sort_by_name_ndx.
+
 2020-06-06  Mark Wielaard  
 
* nm.c (show_symbols_sysv): Skip no name and STT_FILE symbols.
diff --git a/src/nm.c b/src/nm.c
index 8302a98c..a6334743 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -1,5 +1,5 @@
 /* Print symbol information from ELF file in human-readable form.
-   Copyright (C) 2000-2008, 2009, 2011, 2012, 2014, 2015 Red Hat, Inc.
+   Copyright (C) 2000-2008, 2009, 2011, 2012, 2014, 2015, 2020 Red Hat, Inc.
This file is part of elfutils.
Written by Ulrich Drepper , 2000.
 
@@ -1153,7 +1153,8 @@ sort_by_address (const void *p1, const void *p2)
   return reverse_sort ? -result : result;
 }
 
-static Elf_Data *sort_by_name_strtab;
+static Elf *sort_by_name_elf;
+static size_t sort_by_name_ndx;
 
 static int
 sort_by_name (const void *p1, const void *p2)
@@ -1161,8 +1162,10 @@ sort_by_name (const void *p1, const void *p2)
   GElf_SymX *s1 = (GElf_SymX *) p1;
   GElf_SymX *s2 = (GElf_SymX *) p2;
 
-  const char *n1 = sort_by_name_strtab->d_buf + s1->sym.st_name;
-  const char *n2 = sort_by_name_strtab->d_buf + s2->sym.st_name;
+  const char *n1 = elf_strptr (sort_by_name_elf, sort_by_name_ndx,
+  s1->sym.st_name) ?: "";
+  const char *n2 = elf_strptr (sort_by_name_elf, sort_by_name_ndx,
+  s2->sym.st_name) ?: "";
 
   int result = strcmp (n1, n2);
 
@@ -1475,8 +1478,8 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehdr *ehdr,
   /* Sort the entries according to the users wishes.  */
   if (sort == sort_name)
 {
-  sort_by_name_strtab = elf_getdata (elf_getscn (ebl->elf, shdr->sh_link),
-NULL);
+  sort_by_name_elf = ebl->elf;
+  sort_by_name_ndx = shdr->sh_link;
   qsort (sym_mem, nentries, sizeof (GElf_SymX), sort_by_name);
 }
   else if (sort == sort_numeric)
-- 
2.18.4



[Bug debuginfod/25509] Break a cyclic dependency by core packages

2020-06-07 Thread mark at klomp dot org via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=25509

--- Comment #7 from Mark Wielaard  ---
So there are two ideas here:

- Split --disable-debuginfod which currently disables building
  debuginfod (the server), libdebuginfod (the library) and
  debuginfod-find (the helper binaries) in two:
  --disable-debuginfod to disable building of the server.
  --disable-libdebuginfod to disable building of the library and helper binary.

- Introduce a dummy-libdebuginfod which has the same interface as
  libdebuginfod, so applications (during bootstrapping) can link to
  it. But which would not link against libcurl and all functions would
  simply fail.

I assume that --disable-libdebuginfod would mean you cannot have
--enable-debuginfod (because debuginfod links against libdebuginfod). And that
--enable-dummy-libdebuginfod would imply --disable-libdebuginfod because they
provide the same library. I assume that debuginfod-find would be build if
either --enable-libdebuginfod or --enable-dummy-libdebuginfod is given (in the
last case it would simply not do anything useful, but would show the dummy
"works").

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug tools/25793] eu-readelf -w dumps incomplete even if debuginfod available

2020-06-07 Thread mark at klomp dot org via Elfutils-devel
https://sourceware.org/bugzilla/show_bug.cgi?id=25793

--- Comment #3 from Mark Wielaard  ---
We could maybe add something like --dwarf=follow-links to eu-readelf. But the
DWARF information dumping is already somewhat different from the rest of
eu-readelf. The basic idea of eu-readelf is that you can dump headers, segments
and sections data.  This is somewhat lower level than what you are usually
after when using DWARF. If you look at how eu-readelf dumps various .debug
sections you'll see that it really just dumps the data, and doesn't use libdw
at all. There are sometimes two ways to dump the section data
(--debug-dump=line and --debug-dump=decodedline), one which dumps the "raw"
data and one which uses libdw to decode the data first. So maybe we really need
a new tool to dump "decoded" DWARF, which isn't concerned with how the DWARF
data is precisely encoded, but just shows the information. For such a tool
(eu-dwarfdump ?) it would make perfect sense to follow, search and download
extra files when necessary.

-- 
You are receiving this mail because:
You are on the CC list for the bug.