]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwfl_offline_section_address: replace asserts with early return
authorAaron Merey <amerey@redhat.com>
Wed, 1 Nov 2023 20:15:16 +0000 (16:15 -0400)
committerAaron Merey <amerey@redhat.com>
Wed, 1 Nov 2023 23:29:16 +0000 (19:29 -0400)
dwfl_offline_section_address asserts that the current module is ET_REL.

A possibly corrupt .gnu_debuglink can cause an abort by calling
dwfl_offline_section_address on an ET_DYN module.

Prevent this abort and similar ones by replacing
dwfl_offline_section_address initial asserts with an early return.

https://sourceware.org/bugzilla/show_bug.cgi?id=30980

Signed-off-by: Aaron Merey <amerey@redhat.com>
libdwfl/offline.c

index e090b42bb5136d06d0a005ecea0b2d873e4afbc2..52539fe371f6aac542beb719502f967a17668d79 100644 (file)
@@ -50,10 +50,11 @@ dwfl_offline_section_address (Dwfl_Module *mod,
                              const GElf_Shdr *shdr __attribute__ ((unused)),
                              Dwarf_Addr *addr)
 {
-  assert (mod->e_type == ET_REL);
-  assert (shdr->sh_addr == 0);
-  assert (shdr->sh_flags & SHF_ALLOC);
-  assert (shndx != 0);
+  if (mod->e_type != ET_REL
+      || shdr->sh_addr != 0
+      || !(shdr->sh_flags & SHF_ALLOC)
+      || shndx == 0)
+    return -1;
 
   if (mod->debug.elf == NULL)
     /* We are only here because sh_addr is zero even though layout is complete.