]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
_bfd_elf_get_dynamic_symbols
authorAlan Modra <amodra@gmail.com>
Sat, 18 Jan 2025 22:05:22 +0000 (08:35 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 20 Jan 2025 07:46:15 +0000 (18:16 +1030)
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.

bfd/elf.c

index 37b87ee13dabcef6b1b469c6adeb92d869ecaf4a..4fa8a2a7911eb0f7c31d06109a6fca5687a88516 100644 (file)
--- 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)