bfd, sparc: issue an error when reading relocations with invalid symbol references.
authorJose E. Marchesi <jose.marchesi@oracle.com>
Tue, 4 Sep 2018 17:02:38 +0000 (19:02 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Tue, 4 Sep 2018 18:31:41 +0000 (20:31 +0200)
The function `elf64_sparc_slurp_one_reloc_table' in elf64-sparc.c
currently checks that the symbol indexes read in the r_sym fields of
relocations are in range.  This is done for both dynamic and
non-dynamic symbols.  This avoids subsequent invalid memory accesses.
However, no error is issued to the user.

This patch makes BFD to issue an error when the read symbol index is
out of range, following the same behavior implemented in both the
generic ELF routines and other ELF backends (such as mips64).

Tested in x86_64-linux-gnu, sparc64-linux-gnu, and
--enable-targets=all.

2018-09-04  Jose E. Marchesi  <jose.marchesi@oracle.com>

            * elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Issue an
            error when an invalid symbol index is retrieved in ELF64_R_SYM of
            a relocation seen in an input file.

bfd/ChangeLog
bfd/elf64-sparc.c

index 9a3b9b1ec2875cd8f616bfda68dcfc549c22d6dd..22837e0f0e856f98f09454b908dcc29070d89507 100644 (file)
@@ -1,3 +1,9 @@
+2018-09-04  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+       * elf64-sparc.c (elf64_sparc_slurp_one_reloc_table): Issue an
+       error when an invalid symbol index is retrieved in ELF64_R_SYM of
+       a relocation seen in an input file.
+
 2018-09-03  Jozef Lawrynowicz <jozef.l@mittosystems.com>
            Alan Modra  <amodra@gmail.com>
 
index 8c45d3257e43511658a89b2f3ef8de70d72639f2..41e1b7acf7e07b6fccdf04b296921014b13ae27d 100644 (file)
@@ -97,12 +97,20 @@ elf64_sparc_slurp_one_reloc_table (bfd *abfd, asection *asect,
       else
        relent->address = rela.r_offset - asect->vma;
 
-      if (ELF64_R_SYM (rela.r_info) == STN_UNDEF
-         /* PR 17512: file: 996185f8.  */
-         || (!dynamic && ELF64_R_SYM(rela.r_info) > bfd_get_symcount(abfd))
-         || (dynamic
-             && ELF64_R_SYM(rela.r_info) > bfd_get_dynamic_symcount(abfd)))
+      if (ELF64_R_SYM (rela.r_info) == STN_UNDEF)
        relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
+      else if (/* PR 17512: file: 996185f8.  */
+               (!dynamic && ELF64_R_SYM(rela.r_info) > bfd_get_symcount(abfd))
+               || (dynamic
+                   && ELF64_R_SYM(rela.r_info) > bfd_get_dynamic_symcount(abfd)))
+        {
+          _bfd_error_handler
+           /* xgettext:c-format */
+           (_("%pB(%pA): relocation %d has invalid symbol index %ld"),
+            abfd, asect, i, (long) ELF64_R_SYM (rela.r_info));
+         bfd_set_error (bfd_error_bad_value);
+         relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
+        }
       else
        {
          asymbol **ps, *s;
This page took 0.031689 seconds and 4 git commands to generate.