]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Never relocate value against section zero (load address).
authorMark Wielaard <mjw@redhat.com>
Sun, 7 Dec 2014 19:26:56 +0000 (20:26 +0100)
committerMark Wielaard <mjw@redhat.com>
Thu, 11 Dec 2014 14:11:53 +0000 (15:11 +0100)
This really is just a robustify patch in case section zero got the
wrong section flags set. In that case __libdwfl_relocate_value might
call dwfl_offline_section_address which might assert (because it isn't
prepared to handle section zero). elf_nextscn will never see section zero.
So be explicit in dwfl_offline_section_address and immediately assert
when shndx is zero. And handle section zero immediately by not relocating
the value in __libdwfl_relocate_value.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdwfl/ChangeLog
libdwfl/offline.c
libdwfl/relocate.c

index 03faecf1cc2b57bc7078a9627f68f44f9ea3c86f..6eec018f9ef61dfc9b11ea5b29004cd2b653b3be 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-07  Mark Wielaard  <mjw@redhat.com>
+
+       * offline.c (dwfl_offline_section_address): Assert shndx is not zero.
+       * relocate.c (__libdwfl_relocate_value): Don't relocate against
+       section zero.
+
 2014-11-29  Mark Wielaard  <mjw@redhat.com>
 
        * relocate.c (relocate_section): Check relocation section and target
index 28d2782e8a879a2ef6e18973738aacb3427b25e2..982ceab0288b453396038d079e7967268b9b12c2 100644 (file)
@@ -48,6 +48,7 @@ dwfl_offline_section_address (Dwfl_Module *mod,
   assert (mod->e_type == ET_REL);
   assert (shdr->sh_addr == 0);
   assert (shdr->sh_flags & SHF_ALLOC);
+  assert (shndx != 0);
 
   if (mod->debug.elf == NULL)
     /* We are only here because sh_addr is zero even though layout is complete.
index 6862189ceb87f3d1003b12b2146e09d786ac7b7a..fc8ae233fccc20172c2b921a01da6757df639a98 100644 (file)
@@ -38,6 +38,12 @@ internal_function
 __libdwfl_relocate_value (Dwfl_Module *mod, Elf *elf, size_t *shstrndx,
                          Elf32_Word shndx, GElf_Addr *value)
 {
+  /* No adjustment needed for section zero, it is never loaded.
+     Handle it first, just in case the ELF file has strange section
+     zero flags set.  */
+  if (shndx == 0)
+    return DWFL_E_NOERROR;
+
   Elf_Scn *refscn = elf_getscn (elf, shndx);
   GElf_Shdr refshdr_mem, *refshdr = gelf_getshdr (refscn, &refshdr_mem);
   if (refshdr == NULL)