diff options
author | Alan Modra <amodra@gmail.com> | 2021-10-06 09:54:56 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-10-06 11:24:29 +1030 |
commit | 55e3926e79937da55da3eaad3b15b4c099071976 (patch) | |
tree | 74d5010cece6e8cb4cde5c92d70acc0c090ba6ef /binutils | |
parent | 79fa3c401c650521ff771f86810597dd3d3bf75c (diff) | |
download | gdb-55e3926e79937da55da3eaad3b15b4c099071976.zip gdb-55e3926e79937da55da3eaad3b15b4c099071976.tar.gz gdb-55e3926e79937da55da3eaad3b15b4c099071976.tar.bz2 |
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.
Diffstat (limited to 'binutils')
-rw-r--r-- | binutils/objdump.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c index 27bfb42..fdffb8d 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 |