This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] PR24337, segfault in _bfd_elf_rela_local_sym


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ff31e135f04b2773e10d3e5072776c1072edbfb

commit 1ff31e135f04b2773e10d3e5072776c1072edbfb
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Mar 15 16:49:42 2019 +1030

    PR24337, segfault in _bfd_elf_rela_local_sym
    
    	PR 24337
    	* elf.c (_bfd_elf_rela_local_sym): Don't segfault on NULL sec.
    	(_bfd_elf_rel_local_sym): Likewise.

Diff:
---
 bfd/ChangeLog | 6 ++++++
 bfd/elf.c     | 9 +++++----
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index b1011b1..eacd828 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
 2019-03-15  Alan Modra  <amodra@gmail.com>
 
+	PR 24337
+	* elf.c (_bfd_elf_rela_local_sym): Don't segfault on NULL sec.
+	(_bfd_elf_rel_local_sym): Likewise.
+
+2019-03-15  Alan Modra  <amodra@gmail.com>
+
 	PR 24336
 	* elflink.c (elf_link_read_relocs_from_section): Handle fuzzed
 	object files with sh_size not a multiple of sh_entsize.
diff --git a/bfd/elf.c b/bfd/elf.c
index 73fb869..585bf3c 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -11822,9 +11822,10 @@ _bfd_elf_rela_local_sym (bfd *abfd,
   asection *sec = *psec;
   bfd_vma relocation;
 
-  relocation = (sec->output_section->vma
-		+ sec->output_offset
-		+ sym->st_value);
+  relocation = sym->st_value;
+  if (sec == NULL)
+    return relocation;
+  relocation += sec->output_section->vma + sec->output_offset;
   if ((sec->flags & SEC_MERGE)
       && ELF_ST_TYPE (sym->st_info) == STT_SECTION
       && sec->sec_info_type == SEC_INFO_TYPE_MERGE)
@@ -11858,7 +11859,7 @@ _bfd_elf_rel_local_sym (bfd *abfd,
 {
   asection *sec = *psec;
 
-  if (sec->sec_info_type != SEC_INFO_TYPE_MERGE)
+  if (sec == NULL || sec->sec_info_type != SEC_INFO_TYPE_MERGE)
     return sym->st_value + addend;
 
   return _bfd_merged_section_offset (abfd, psec,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]