diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 0a92044f3b..710b790caf 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2015-12-07 Alan Modra + + PR19323 + * elfcode.h (elf_object_p): Check for ridiculous e_shnum and + e_phnum values. + 2015-12-07 Alan Modra * reloc.c (BFD_RELOC_PPC64_ENTRY): New. diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 26af1d18c2..915c8d5f88 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -676,6 +676,10 @@ elf_object_p (bfd *abfd) Elf_Internal_Shdr *shdrp; unsigned int num_sec; +#ifndef BFD64 + if (i_ehdrp->e_shnum > ((bfd_size_type) -1) / sizeof (*i_shdrp)) + goto got_wrong_format_error; +#endif amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum; i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt); if (!i_shdrp) @@ -766,7 +770,11 @@ elf_object_p (bfd *abfd) Elf_Internal_Phdr *i_phdr; unsigned int i; - amt = i_ehdrp->e_phnum * sizeof (Elf_Internal_Phdr); +#ifndef BFD64 + if (i_ehdrp->e_phnum > ((bfd_size_type) -1) / sizeof (*i_phdr)) + goto got_wrong_format_error; +#endif + amt = i_ehdrp->e_phnum * sizeof (*i_phdr); elf_tdata (abfd)->phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt); if (elf_tdata (abfd)->phdr == NULL) goto got_no_match;