|
|
58725c |
diff -rup binutils.orig/bfd/aoutx.h binutils-2.27/bfd/aoutx.h
|
|
|
58725c |
--- binutils.orig/bfd/aoutx.h 2019-01-14 16:10:59.344958851 +0000
|
|
|
58725c |
+++ binutils-2.27/bfd/aoutx.h 2019-01-14 16:11:46.893598783 +0000
|
|
|
58725c |
@@ -118,6 +118,7 @@ DESCRIPTION
|
|
|
58725c |
#define KEEPIT udata.i
|
|
|
58725c |
|
|
|
58725c |
#include "sysdep.h"
|
|
|
58725c |
+#include <limits.h>
|
|
|
58725c |
#include "bfd.h"
|
|
|
58725c |
#include "safe-ctype.h"
|
|
|
58725c |
#include "bfdlink.h"
|
|
|
58725c |
@@ -2465,6 +2466,8 @@ NAME (aout, canonicalize_reloc) (bfd *ab
|
|
|
58725c |
long
|
|
|
58725c |
NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
|
|
|
58725c |
{
|
|
|
58725c |
+ bfd_size_type count;
|
|
|
58725c |
+
|
|
|
58725c |
if (bfd_get_format (abfd) != bfd_object)
|
|
|
58725c |
{
|
|
|
58725c |
bfd_set_error (bfd_error_invalid_operation);
|
|
|
58725c |
@@ -2472,26 +2475,25 @@ NAME (aout, get_reloc_upper_bound) (bfd
|
|
|
58725c |
}
|
|
|
58725c |
|
|
|
58725c |
if (asect->flags & SEC_CONSTRUCTOR)
|
|
|
58725c |
- return sizeof (arelent *) * (asect->reloc_count + 1);
|
|
|
58725c |
-
|
|
|
58725c |
- if (asect == obj_datasec (abfd))
|
|
|
58725c |
- return sizeof (arelent *)
|
|
|
58725c |
- * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
|
|
|
58725c |
- + 1);
|
|
|
58725c |
-
|
|
|
58725c |
- if (asect == obj_textsec (abfd))
|
|
|
58725c |
- return sizeof (arelent *)
|
|
|
58725c |
- * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
|
|
|
58725c |
- + 1);
|
|
|
58725c |
-
|
|
|
58725c |
- if (asect == obj_bsssec (abfd))
|
|
|
58725c |
- return sizeof (arelent *);
|
|
|
58725c |
-
|
|
|
58725c |
- if (asect == obj_bsssec (abfd))
|
|
|
58725c |
- return 0;
|
|
|
58725c |
+ count = asect->reloc_count;
|
|
|
58725c |
+ else if (asect == obj_datasec (abfd))
|
|
|
58725c |
+ count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
|
|
|
58725c |
+ else if (asect == obj_textsec (abfd))
|
|
|
58725c |
+ count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
|
|
|
58725c |
+ else if (asect == obj_bsssec (abfd))
|
|
|
58725c |
+ count = 0;
|
|
|
58725c |
+ else
|
|
|
58725c |
+ {
|
|
|
58725c |
+ bfd_set_error (bfd_error_invalid_operation);
|
|
|
58725c |
+ return -1;
|
|
|
58725c |
+ }
|
|
|
58725c |
|
|
|
58725c |
- bfd_set_error (bfd_error_invalid_operation);
|
|
|
58725c |
- return -1;
|
|
|
58725c |
+ if (count >= LONG_MAX / sizeof (arelent *))
|
|
|
58725c |
+ {
|
|
|
58725c |
+ bfd_set_error (bfd_error_file_too_big);
|
|
|
58725c |
+ return -1;
|
|
|
58725c |
+ }
|
|
|
58725c |
+ return (count + 1) * sizeof (arelent *);
|
|
|
58725c |
}
|
|
|
58725c |
|
|
|
58725c |
long
|
|
|
58725c |
diff -rup binutils.orig/bfd/elf.c binutils-2.27/bfd/elf.c
|
|
|
58725c |
--- binutils.orig/bfd/elf.c 2019-01-14 16:10:59.331958950 +0000
|
|
|
58725c |
+++ binutils-2.27/bfd/elf.c 2019-01-14 16:11:52.525556135 +0000
|
|
|
58725c |
@@ -35,6 +35,7 @@ SECTION
|
|
|
58725c |
/* For sparc64-cross-sparc32. */
|
|
|
58725c |
#define _SYSCALL32
|
|
|
58725c |
#include "sysdep.h"
|
|
|
58725c |
+#include <limits.h>
|
|
|
58725c |
#include "bfd.h"
|
|
|
58725c |
#include "bfdlink.h"
|
|
|
58725c |
#include "libbfd.h"
|
|
|
58725c |
@@ -7769,11 +7770,16 @@ Unable to find equivalent output section
|
|
|
58725c |
long
|
|
|
58725c |
_bfd_elf_get_symtab_upper_bound (bfd *abfd)
|
|
|
58725c |
{
|
|
|
58725c |
- long symcount;
|
|
|
58725c |
+ bfd_size_type symcount;
|
|
|
58725c |
long symtab_size;
|
|
|
58725c |
Elf_Internal_Shdr *hdr = &elf_tdata (abfd)->symtab_hdr;
|
|
|
58725c |
|
|
|
58725c |
symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
|
|
|
58725c |
+ if (symcount >= LONG_MAX / sizeof (asymbol *))
|
|
|
58725c |
+ {
|
|
|
58725c |
+ bfd_set_error (bfd_error_file_too_big);
|
|
|
58725c |
+ return -1;
|
|
|
58725c |
+ }
|
|
|
58725c |
symtab_size = (symcount + 1) * (sizeof (asymbol *));
|
|
|
58725c |
if (symcount > 0)
|
|
|
58725c |
symtab_size -= sizeof (asymbol *);
|
|
|
58725c |
@@ -7784,7 +7790,7 @@ _bfd_elf_get_symtab_upper_bound (bfd *ab
|
|
|
58725c |
long
|
|
|
58725c |
_bfd_elf_get_dynamic_symtab_upper_bound (bfd *abfd)
|
|
|
58725c |
{
|
|
|
58725c |
- long symcount;
|
|
|
58725c |
+ bfd_size_type symcount;
|
|
|
58725c |
long symtab_size;
|
|
|
58725c |
Elf_Internal_Shdr *hdr = &elf_tdata (abfd)->dynsymtab_hdr;
|
|
|
58725c |
|
|
|
58725c |
@@ -7795,6 +7801,11 @@ _bfd_elf_get_dynamic_symtab_upper_bound
|
|
|
58725c |
}
|
|
|
58725c |
|
|
|
58725c |
symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
|
|
|
58725c |
+ if (symcount >= LONG_MAX / sizeof (asymbol *))
|
|
|
58725c |
+ {
|
|
|
58725c |
+ bfd_set_error (bfd_error_file_too_big);
|
|
|
58725c |
+ return -1;
|
|
|
58725c |
+ }
|
|
|
58725c |
symtab_size = (symcount + 1) * (sizeof (asymbol *));
|
|
|
58725c |
if (symcount > 0)
|
|
|
58725c |
symtab_size -= sizeof (asymbol *);
|
|
|
58725c |
@@ -7864,7 +7875,7 @@ _bfd_elf_canonicalize_dynamic_symtab (bf
|
|
|
58725c |
long
|
|
|
58725c |
_bfd_elf_get_dynamic_reloc_upper_bound (bfd *abfd)
|
|
|
58725c |
{
|
|
|
58725c |
- long ret;
|
|
|
58725c |
+ bfd_size_type count;
|
|
|
58725c |
asection *s;
|
|
|
58725c |
|
|
|
58725c |
if (elf_dynsymtab (abfd) == 0)
|
|
|
58725c |
@@ -7873,15 +7884,20 @@ _bfd_elf_get_dynamic_reloc_upper_bound (
|
|
|
58725c |
return -1;
|
|
|
58725c |
}
|
|
|
58725c |
|
|
|
58725c |
- ret = sizeof (arelent *);
|
|
|
58725c |
+ count = 1;
|
|
|
58725c |
for (s = abfd->sections; s != NULL; s = s->next)
|
|
|
58725c |
if (elf_section_data (s)->this_hdr.sh_link == elf_dynsymtab (abfd)
|
|
|
58725c |
&& (elf_section_data (s)->this_hdr.sh_type == SHT_REL
|
|
|
58725c |
|| elf_section_data (s)->this_hdr.sh_type == SHT_RELA))
|
|
|
58725c |
- ret += ((s->size / elf_section_data (s)->this_hdr.sh_entsize)
|
|
|
58725c |
- * sizeof (arelent *));
|
|
|
58725c |
-
|
|
|
58725c |
- return ret;
|
|
|
58725c |
+ {
|
|
|
58725c |
+ count += s->size / elf_section_data (s)->this_hdr.sh_entsize;
|
|
|
58725c |
+ if (count > LONG_MAX / sizeof (arelent *))
|
|
|
58725c |
+ {
|
|
|
58725c |
+ bfd_set_error (bfd_error_file_too_big);
|
|
|
58725c |
+ return -1;
|
|
|
58725c |
+ }
|
|
|
58725c |
+ }
|
|
|
58725c |
+ return count * sizeof (arelent *);
|
|
|
58725c |
}
|
|
|
58725c |
|
|
|
58725c |
/* Canonicalize the dynamic relocation entries. Note that we return the
|
|
|
58725c |
|