]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Replace assertions with error return values, thus ensuring an illegal memory access...
authorNick Clifton <nickc@redhat.com>
Fri, 30 May 2025 12:00:59 +0000 (13:00 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 30 May 2025 12:00:59 +0000 (13:00 +0100)
PR 33020

bfd/elf-strtab.c
bfd/elf.c

index 9b0b0b8ec60548a85d9c189a651b66adf09698c4..52a0895fb43eb85737f48f70559b55a7f74abb54 100644 (file)
@@ -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;
 }
index 3073f860621f390dd5f6dabb8795bb8f6ec36c6f..61910f8909acde5400bc27afd13cc82d7663eb72 100644 (file)
--- 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;