]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Skip trying to uncompress sections without a name
authorMark Wielaard <mark@klomp.org>
Sat, 8 Feb 2025 23:07:39 +0000 (00:07 +0100)
committerMark Wielaard <mark@klomp.org>
Fri, 14 Feb 2025 07:55:10 +0000 (08:55 +0100)
When combining eu-readelf -z with -x or -p to dump the data or strings
in an (corrupted ELF) unnamed numbered section eu-readelf could crash
trying to check whether the section name starts with .zdebug. Fix this
by skipping sections without a name.

   * src/readelf.c (dump_data_section): Don't try to gnu decompress a
   section without a name.
   (print_string_section): Likewise.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/readelf.c

index 21b92a08a6b6d1e5236e02a8f607f6e3491be23c..da37921602f1b1f250370e2f061d4be4e83b62d1 100644 (file)
@@ -13327,7 +13327,7 @@ dump_data_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
                        _("Couldn't uncompress section"),
                        elf_ndxscn (scn));
            }
-         else if (startswith (name, ".zdebug"))
+         else if (name && startswith (name, ".zdebug"))
            {
              if (elf_compress_gnu (scn, 0, 0) < 0)
                printf ("WARNING: %s [%zd]\n",
@@ -13378,7 +13378,7 @@ print_string_section (Elf_Scn *scn, const GElf_Shdr *shdr, const char *name)
                        _("Couldn't uncompress section"),
                        elf_ndxscn (scn));
            }
-         else if (startswith (name, ".zdebug"))
+         else if (name && startswith (name, ".zdebug"))
            {
              if (elf_compress_gnu (scn, 0, 0) < 0)
                printf ("WARNING: %s [%zd]\n",