From: Nick Clifton Date: Fri, 30 May 2025 12:00:59 +0000 (+0100) Subject: Replace assertions with error return values, thus ensuring an illegal memory access... X-Git-Tag: binutils-2_45~452 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=429fb15134cfbdafe2b203086ee05d827726b63b;p=thirdparty%2Fbinutils-gdb.git Replace assertions with error return values, thus ensuring an illegal memory access does not occur. PR 33020 --- diff --git a/bfd/elf-strtab.c b/bfd/elf-strtab.c index 9b0b0b8ec60..52a0895fb43 100644 --- a/bfd/elf-strtab.c +++ b/bfd/elf-strtab.c @@ -285,12 +285,11 @@ _bfd_elf_strtab_offset (struct elf_strtab_hash *tab, size_t idx) { struct elf_strtab_hash_entry *entry; - if (idx == 0) + if (idx == 0 || idx >= tab->size || tab->sec_size == 0) return 0; - BFD_ASSERT (idx < tab->size); - BFD_ASSERT (tab->sec_size); entry = tab->array[idx]; - BFD_ASSERT (entry->refcount > 0); + if (entry == NULL || entry->refcount == 0) + return 0; entry->refcount--; return tab->array[idx]->u.index; } diff --git a/bfd/elf.c b/bfd/elf.c index 3073f860621..61910f8909a 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -7161,9 +7161,12 @@ _bfd_elf_write_object_contents (bfd *abfd) { /* Don't set the sh_name field without section header. */ if ((abfd->flags & BFD_NO_SECTION_HEADER) == 0) - i_shdrp[count]->sh_name - = _bfd_elf_strtab_offset (elf_shstrtab (abfd), - i_shdrp[count]->sh_name); + { + i_shdrp[count]->sh_name + = _bfd_elf_strtab_offset (elf_shstrtab (abfd), + i_shdrp[count]->sh_name); + /* FIXME: If we could not set the section name, should we tell the user ? */ + } if (bed->elf_backend_section_processing) if (!(*bed->elf_backend_section_processing) (abfd, i_shdrp[count])) return false;