Blame SOURCES/binutils-CVE-2020-35448.patch

1709e2
diff -rup binutils.orig/bfd/elf.c binutils-2.35/bfd/elf.c
1709e2
--- binutils.orig/bfd/elf.c	2021-04-19 10:49:21.757290990 +0100
1709e2
+++ binutils-2.35/bfd/elf.c	2021-04-19 10:50:28.309839285 +0100
1709e2
@@ -12534,7 +12534,9 @@ _bfd_elf_slurp_secondary_reloc_section (
1709e2
       Elf_Internal_Shdr * hdr = & elf_section_data (relsec)->this_hdr;
1709e2
 
1709e2
       if (hdr->sh_type == SHT_SECONDARY_RELOC
1709e2
-	  && hdr->sh_info == (unsigned) elf_section_data (sec)->this_idx)
1709e2
+	  && hdr->sh_info == (unsigned) elf_section_data (sec)->this_idx
1709e2
+	  && (hdr->sh_entsize == ebd->s->sizeof_rel
1709e2
+	      || hdr->sh_entsize == ebd->s->sizeof_rela))
1709e2
 	{
1709e2
 	  bfd_byte * native_relocs;
1709e2
 	  bfd_byte * native_reloc;
1709e2
diff -rup binutils.orig/bfd/elfcode.h binutils-2.35/bfd/elfcode.h
1709e2
--- binutils.orig/bfd/elfcode.h	2021-04-19 10:49:21.767290922 +0100
1709e2
+++ binutils-2.35/bfd/elfcode.h	2021-04-19 10:52:22.196066303 +0100
1709e2
@@ -568,7 +568,7 @@ elf_object_p (bfd *abfd)
1709e2
 
1709e2
   /* If this is a relocatable file and there is no section header
1709e2
      table, then we're hosed.  */
1709e2
-  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
1709e2
+  if (i_ehdrp->e_shoff < sizeof (x_ehdr) && i_ehdrp->e_type == ET_REL)
1709e2
     goto got_wrong_format_error;
1709e2
 
1709e2
   /* As a simple sanity check, verify that what BFD thinks is the
1709e2
@@ -578,7 +578,7 @@ elf_object_p (bfd *abfd)
1709e2
     goto got_wrong_format_error;
1709e2
 
1709e2
   /* Further sanity check.  */
1709e2
-  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_shnum != 0)
1709e2
+  if (i_ehdrp->e_shoff < sizeof (x_ehdr) && i_ehdrp->e_shnum != 0)
1709e2
     goto got_wrong_format_error;
1709e2
 
1709e2
   ebd = get_elf_backend_data (abfd);
1709e2
@@ -615,7 +615,7 @@ elf_object_p (bfd *abfd)
1709e2
       && ebd->elf_osabi != ELFOSABI_NONE)
1709e2
     goto got_wrong_format_error;
1709e2
 
1709e2
-  if (i_ehdrp->e_shoff != 0)
1709e2
+  if (i_ehdrp->e_shoff >= sizeof (x_ehdr))
1709e2
     {
1709e2
       file_ptr where = (file_ptr) i_ehdrp->e_shoff;
1709e2
 
1709e2
@@ -807,7 +807,7 @@ elf_object_p (bfd *abfd)
1709e2
 	}
1709e2
     }
1709e2
 
1709e2
-  if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff != 0)
1709e2
+  if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff >= sizeof (x_ehdr))
1709e2
     {
1709e2
       unsigned int num_sec;
1709e2