Skip to content

Commit 429fb15

Browse files
committed
Replace assertions with error return values, thus ensuring an illegal memory access does not occur.
PR 33020
1 parent 777ca81 commit 429fb15

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

bfd/elf-strtab.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,11 @@ _bfd_elf_strtab_offset (struct elf_strtab_hash *tab, size_t idx)
285285
{
286286
struct elf_strtab_hash_entry *entry;
287287

288-
if (idx == 0)
288+
if (idx == 0 || idx >= tab->size || tab->sec_size == 0)
289289
return 0;
290-
BFD_ASSERT (idx < tab->size);
291-
BFD_ASSERT (tab->sec_size);
292290
entry = tab->array[idx];
293-
BFD_ASSERT (entry->refcount > 0);
291+
if (entry == NULL || entry->refcount == 0)
292+
return 0;
294293
entry->refcount--;
295294
return tab->array[idx]->u.index;
296295
}

bfd/elf.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7161,9 +7161,12 @@ _bfd_elf_write_object_contents (bfd *abfd)
71617161
{
71627162
/* Don't set the sh_name field without section header. */
71637163
if ((abfd->flags & BFD_NO_SECTION_HEADER) == 0)
7164-
i_shdrp[count]->sh_name
7165-
= _bfd_elf_strtab_offset (elf_shstrtab (abfd),
7166-
i_shdrp[count]->sh_name);
7164+
{
7165+
i_shdrp[count]->sh_name
7166+
= _bfd_elf_strtab_offset (elf_shstrtab (abfd),
7167+
i_shdrp[count]->sh_name);
7168+
/* FIXME: If we could not set the section name, should we tell the user ? */
7169+
}
71677170
if (bed->elf_backend_section_processing)
71687171
if (!(*bed->elf_backend_section_processing) (abfd, i_shdrp[count]))
71697172
return false;

0 commit comments

Comments
 (0)