From: Alan Modra Date: Tue, 5 Oct 2021 23:24:56 +0000 (+1030) Subject: PR28401, invalid section name lookup X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=55e3926e79937da55da3eaad3b15b4c099071976;p=binutils-gdb.git PR28401, invalid section name lookup The PR28401 testcase has a section named "", ie. an empty string. This results in some silly behaviour in load_debug_section, and dump_dwarf_section. Fix that. Note that this patch doesn't correct the main complaint in PR28401, "failed to allocate", since malloc failures on sections having huge bogus sizes are to be expected. We can't safely catch all such cases by comparing with file size, for example, where sections contain compressed data. PR 28401 * objdump.c (load_debug_section): Don't attempt to retrieve empty name sections. (dump_dwarf_section): Likewise. --- diff --git a/binutils/objdump.c b/binutils/objdump.c index 27bfb420399..fdffb8d5263 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -3711,6 +3711,7 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file) struct dwarf_section *section = &debug_displays [debug].section; bfd *abfd = (bfd *) file; asection *sec; + const char *name; /* If it is already loaded, do nothing. */ if (section->start != NULL) @@ -3719,24 +3720,24 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file) return true; } /* Locate the debug section. */ - sec = bfd_get_section_by_name (abfd, section->uncompressed_name); - if (sec != NULL) - section->name = section->uncompressed_name; - else + name = section->uncompressed_name; + sec = bfd_get_section_by_name (abfd, name); + if (sec == NULL) { - sec = bfd_get_section_by_name (abfd, section->compressed_name); - if (sec != NULL) - section->name = section->compressed_name; - else - { - sec = bfd_get_section_by_name (abfd, section->xcoff_name); - if (sec != NULL) - section->name = section->xcoff_name; - } + name = section->compressed_name; + if (*name) + sec = bfd_get_section_by_name (abfd, name); + } + if (sec == NULL) + { + name = section->xcoff_name; + if (*name) + sec = bfd_get_section_by_name (abfd, name); } if (sec == NULL) return false; + section->name = name; return load_specific_debug_section (debug, sec, file); } @@ -3809,6 +3810,9 @@ dump_dwarf_section (bfd *abfd, asection *section, const char *match; int i; + if (*name == 0) + return; + if (startswith (name, ".gnu.linkonce.wi.")) match = ".debug_info"; else