aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@mips.com>2018-04-09 13:42:00 +0100
committerMaciej W. Rozycki <macro@mips.com>2018-04-09 13:42:00 +0100
commitaec2e0d252342aa7575aff608e999a36f27a9147 (patch)
tree9a1a5ce7f6f2ba6e37b7e5babdd8a8d3f8aaf07b
parent3f97ba9fc82dbb1bca72fd8a137b2de132348367 (diff)
downloadgdb-aec2e0d252342aa7575aff608e999a36f27a9147.zip
gdb-aec2e0d252342aa7575aff608e999a36f27a9147.tar.gz
gdb-aec2e0d252342aa7575aff608e999a36f27a9147.tar.bz2
MIPS64/BFD: Fix a crash with STN_UNDEF in relocation
Prevent a null BFD pointer dereference and a resulting segmentation fault in `mips_elf64_write_rel' or `mips_elf64_write_rela': Program received signal SIGSEGV, Segmentation fault. 0x0000000000437690 in mips_elf64_write_rela (abfd=0x71e130, sec=0x720700, rela_hdr=0x721ff8, count=0x7fffffffb82c, data=0x7fffffffb88c) at .../bfd/elf64-mips.c:4123 4123 if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec 4124 && ! _bfd_elf_validate_reloc (abfd, ptr)) in the MIPS64 (n64 MIPS) ELF backend whenever the STN_UNDEF symbol index is retrieved from the `r_sym' field of a relocation seen in input while running `objcopy' or `strip'. The reason for the null BFD pointer is that internally in BFD an STN_UNDEF symbol reference resolves to an absolute zero symbol that does not have a BFD associated. Check the pointer then before using it, like the generic ELF backend does in `elf_write_relocs'. This complements the same change made for generic ELF bundled with: commit e35765a9a2eaff0df62757f3e6480c8ba5ab8ee8 Author: Ian Lance Taylor <ian@airs.com> Date: Sun Dec 15 19:59:18 1996 +0000 which (obviously due to a CVS -> GIT repository conversion inaccuracy) seems to be one corresponding to this ChangeLog entry: * elfcode.h (write_relocs): Handle absolute symbol. from: commit c86158e591edd8450f49f8cd75f82e4313d4b6d8 Author: Ian Lance Taylor <ian@airs.com> Date: Fri Aug 30 22:09:51 1996 +0000 ("Add SH ELF support."), which also updated RELA only and not REL (which has been since fixed with: commit 947216bf8f34 ("ELF reloc code tidy"), <https://sourceware.org/ml/binutils/2002-11/msg00727.html>). bfd/ * elf64-mips.c (mips_elf64_write_rel): Handle a NULL BFD pointer in the BFD symbol referred by the relocation. (mips_elf64_write_rela): Likewise.
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/elf64-mips.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index d65d5a8..33127be 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
2018-04-09 Maciej W. Rozycki <macro@mips.com>
+ * elf64-mips.c (mips_elf64_write_rel): Handle a NULL BFD pointer
+ in the BFD symbol referred by the relocation.
+ (mips_elf64_write_rela): Likewise.
+
+2018-04-09 Maciej W. Rozycki <macro@mips.com>
+
* elf64-mips.c (mips_elf64_slurp_one_reloc_table): Issue an
error for out-of-range `r_sym' values.
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index 86e5589..4b9fdf6 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -4038,7 +4038,8 @@ mips_elf64_write_rel (bfd *abfd, asection *sec,
int_rel.r_sym = n;
int_rel.r_ssym = RSS_UNDEF;
- if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
+ if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
+ && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
&& ! _bfd_elf_validate_reloc (abfd, ptr))
{
*failedp = TRUE;
@@ -4137,7 +4138,8 @@ mips_elf64_write_rela (bfd *abfd, asection *sec,
int_rela.r_addend = ptr->addend;
int_rela.r_ssym = RSS_UNDEF;
- if ((*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
+ if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
+ && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
&& ! _bfd_elf_validate_reloc (abfd, ptr))
{
*failedp = TRUE;