_bfd_elf_get_dynamic_symbols
Alan Modra
amodra@gmail.com
Mon Jan 20 07:48:53 GMT 2025
This fixes an error path in _bfd_elf_get_dynamic_symbols, fixes the
minimum size required when reading DT_HASH header, and tidies
formatting in a few places. Nit-fixes all.
Very likely we shouldn't be trying to mmap DT_DYNAMIC as it won't be
large enough for the mmap size threshold.
* elf.c (_bfd_elf_get_dynamic_symbols): Use _bfd_munmap_temporary
in error return path rather than free. Corrent size passed to
offset_from_vma when reading DT_HASH header. Formatting.
diff --git a/bfd/elf.c b/bfd/elf.c
index 37b87ee13da..4fa8a2a7911 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1746,7 +1746,7 @@ get_hash_table_data (bfd *abfd, bfd_size_type number,
i_data = (bfd_vma *) bfd_malloc (number * sizeof (*i_data));
if (i_data == NULL)
{
- free (e_data);
+ _bfd_munmap_temporary (e_data_addr, e_data_size);
return NULL;
}
@@ -1941,7 +1941,7 @@ _bfd_elf_get_dynamic_symbols (bfd *abfd, Elf_Internal_Phdr *phdr,
break;
}
- filepos = offset_from_vma (phdrs, phnum, dt_hash, sizeof (nb),
+ filepos = offset_from_vma (phdrs, phnum, dt_hash, 2 * hash_ent_size,
NULL);
if (filepos == (file_ptr) -1
|| bfd_seek (abfd, filepos, SEEK_SET) != 0
@@ -2012,8 +2012,7 @@ _bfd_elf_get_dynamic_symbols (bfd *abfd, Elf_Internal_Phdr *phdr,
maxchain -= gnusymidx;
filepos = offset_from_vma (phdrs, phnum,
- (buckets_vma +
- 4 * (ngnubuckets + maxchain)),
+ buckets_vma + 4 * (ngnubuckets + maxchain),
4, NULL);
if (filepos == (file_ptr) -1
|| bfd_seek (abfd, filepos, SEEK_SET) != 0)
@@ -2030,7 +2029,7 @@ _bfd_elf_get_dynamic_symbols (bfd *abfd, Elf_Internal_Phdr *phdr,
while ((bfd_get_32 (abfd, nb) & 1) == 0);
filepos = offset_from_vma (phdrs, phnum,
- (buckets_vma + 4 * ngnubuckets),
+ buckets_vma + 4 * ngnubuckets,
4, NULL);
if (filepos == (file_ptr) -1
|| bfd_seek (abfd, filepos, SEEK_SET) != 0)
@@ -2044,8 +2043,7 @@ _bfd_elf_get_dynamic_symbols (bfd *abfd, Elf_Internal_Phdr *phdr,
if (dt_mips_xhash)
{
filepos = offset_from_vma (phdrs, phnum,
- (buckets_vma
- + 4 * (ngnubuckets + maxchain)),
+ buckets_vma + 4 * (ngnubuckets + maxchain),
4, NULL);
if (filepos == (file_ptr) -1
|| bfd_seek (abfd, filepos, SEEK_SET) != 0)
--
Alan Modra
More information about the Binutils
mailing list