diff options
author | Alan Modra <amodra@gmail.com> | 2024-08-25 15:20:21 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2024-08-26 09:40:55 +0930 |
commit | db856d41004301b3a56438efd957ef5cabb91530 (patch) | |
tree | 70068307e2aeaa0a18ed27f9c1ee792c9bb42feb | |
parent | d188dec6ee4073085c53054592c1e099d78d7a87 (diff) | |
download | gdb-db856d41004301b3a56438efd957ef5cabb91530.zip gdb-db856d41004301b3a56438efd957ef5cabb91530.tar.gz gdb-db856d41004301b3a56438efd957ef5cabb91530.tar.bz2 |
PR32109, aborting at bfd/bfd.c:1236 in int _bfd_doprnt
Since bfd_section for .strtab isn't set, print the section index
instead. Also, don't return NULL on this error as that results in
multiple mmap/read of the string table. (We could return NULL if we
arranged to set sh_size zero first, but just what we do with fuzzed
object files is of no concern, and terminating the table might make a
faulty object file usable.)
PR 32109
* elf.c (bfd_elf_get_str_section): Remove outdated comment, and
tweak shstrtabsize test to suit. Don't use string tab bfd_section
in error message, use index instead. Don't return NULL on
unterminated string section, terminate it.
(_bfd_elf_get_dynamic_symbols): Similarly terminate string table
section.
-rw-r--r-- | bfd/elf.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -285,9 +285,7 @@ bfd_elf_get_str_section (bfd *abfd, unsigned int shindex) offset = i_shdrp[shindex]->sh_offset; shstrtabsize = i_shdrp[shindex]->sh_size; - /* Allocate and clear an extra byte at the end, to prevent crashes - in case the string table is not terminated. */ - if (shstrtabsize + 1 <= 1 + if (shstrtabsize == 0 || bfd_seek (abfd, offset, SEEK_SET) != 0 || (shstrtab = _bfd_mmap_readonly_persistent (abfd, shstrtabsize)) == NULL) @@ -297,14 +295,13 @@ bfd_elf_get_str_section (bfd *abfd, unsigned int shindex) the string table over and over. */ i_shdrp[shindex]->sh_size = 0; } - else if (shstrtab[shstrtabsize - 1] != '\0') + else if (shstrtab[shstrtabsize - 1] != 0) { /* It is an error if a string table isn't terminated. */ _bfd_error_handler /* xgettext:c-format */ - (_("%pB(%pA): string table is corrupt"), - abfd, i_shdrp[shindex]->bfd_section); - return NULL; + (_("%pB: string table [%u] is corrupt"), abfd, shindex); + shstrtab[shstrtabsize - 1] = 0; } i_shdrp[shindex]->contents = shstrtab; } @@ -1914,7 +1911,7 @@ _bfd_elf_get_dynamic_symbols (bfd *abfd, Elf_Internal_Phdr *phdr, _bfd_error_handler /* xgettext:c-format */ (_("%pB: DT_STRTAB table is corrupt"), abfd); - goto error_return; + strbuf[dt_strsz - 1] = 0; } /* Get the real symbol count from DT_HASH or DT_GNU_HASH. Prefer |