[binutils-gdb] PR24689, string table corruption

Alan Modra amodra@sourceware.org
Fri Jun 21 07:15:00 GMT 2019


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

commit 890f750a3b053532a4b839a2dd6243076de12031
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Jun 21 11:51:38 2019 +0930

    PR24689, string table corruption
    
    The testcase in the PR had a e_shstrndx section of type SHT_GROUP.
    hdr->contents were initialized by setup_group rather than being read
    from the file, thus last byte was not zero and string dereference ran
    off the end of the buffer.
    
    	PR 24689
    	* elfcode.h (elf_object_p): Check type of e_shstrndx section.

Diff:
---
 bfd/ChangeLog | 5 +++++
 bfd/elfcode.h | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f40f6ed..bc7671e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-21  Alan Modra  <amodra@gmail.com>
+
+	PR 24689
+	* elfcode.h (elf_object_p): Check type of e_shstrndx section.
+
 2019-06-19  Alan Modra  <amodra@gmail.com>
 
 	PR 24697
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index a0487b0..5180f79 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -754,7 +754,8 @@ elf_object_p (bfd *abfd)
   /* A further sanity check.  */
   if (i_ehdrp->e_shnum != 0)
     {
-      if (i_ehdrp->e_shstrndx >= elf_numsections (abfd))
+      if (i_ehdrp->e_shstrndx >= elf_numsections (abfd)
+	  || i_shdrp[i_ehdrp->e_shstrndx].sh_type != SHT_STRTAB)
 	{
 	  /* PR 2257:
 	     We used to just goto got_wrong_format_error here



More information about the Binutils-cvs mailing list