X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felfcode.h;h=ef097f739cddc7e06c3a0e3a6fb65b348e0a3603;hb=e15c3eb45bdc8bd5717fd5ceddcc30c3de07b58f;hp=ec53c3bbd8f65ba6f655293759a8357196e885b0;hpb=92c9bcd479e4cb388a7f286fc42414b115cfc656;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elfcode.h b/bfd/elfcode.h index ec53c3bbd8..ef097f739c 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1,5 +1,5 @@ /* ELF executable support for BFD. - Copyright (C) 1991-2014 Free Software Foundation, Inc. + Copyright (C) 1991-2017 Free Software Foundation, Inc. Written by Fred Fish @ Cygnus Support, from information published in "UNIX System V Release 4, Programmers Guide: ANSI C and @@ -605,13 +605,10 @@ elf_object_p (bfd *abfd) if (i_ehdrp->e_shoff != 0) { - bfd_signed_vma where = i_ehdrp->e_shoff; - - if (where != (file_ptr) where) - goto got_wrong_format_error; + file_ptr where = (file_ptr) i_ehdrp->e_shoff; /* Seek to the section header table in the file. */ - if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0) + if (bfd_seek (abfd, where, SEEK_SET) != 0) goto got_no_match; /* Read the first section header at index 0, and convert to internal @@ -657,19 +654,17 @@ elf_object_p (bfd *abfd) goto got_wrong_format_error; where += (i_ehdrp->e_shnum - 1) * sizeof (x_shdr); - if (where != (file_ptr) where) - goto got_wrong_format_error; if ((bfd_size_type) where <= i_ehdrp->e_shoff) goto got_wrong_format_error; - if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0) + if (bfd_seek (abfd, where, SEEK_SET) != 0) goto got_no_match; if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr)) goto got_no_match; /* Back to where we were. */ where = i_ehdrp->e_shoff + sizeof (x_shdr); - if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0) + if (bfd_seek (abfd, where, SEEK_SET) != 0) goto got_no_match; } } @@ -681,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) @@ -712,7 +711,7 @@ elf_object_p (bfd *abfd) switch (ebd->elf_machine_code) { case EM_386: - case EM_486: + case EM_IAMCU: case EM_X86_64: case EM_OLD_SPARCV9: case EM_SPARC32PLUS: @@ -757,7 +756,9 @@ elf_object_p (bfd *abfd) So we are kind, and reset the string index value to 0 so that at least some processing can be done. */ i_ehdrp->e_shstrndx = SHN_UNDEF; - _bfd_error_handler (_("warning: %s has a corrupt string table index - ignoring"), abfd->filename); + _bfd_error_handler + (_("warning: %B has a corrupt string table index - ignoring"), + abfd); } } else if (i_ehdrp->e_shstrndx != SHN_UNDEF) @@ -771,7 +772,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; @@ -970,6 +975,7 @@ elf_write_out_phdrs (bfd *abfd, while (count--) { Elf_External_Phdr extphdr; + elf_swap_phdr_out (abfd, phdr, &extphdr); if (bfd_bwrite (&extphdr, sizeof (Elf_External_Phdr), abfd) != sizeof (Elf_External_Phdr)) @@ -1182,9 +1188,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) if (verhdr != NULL && verhdr->sh_size / sizeof (Elf_External_Versym) != symcount) { - (*_bfd_error_handler) - (_("%s: version count (%ld) does not match symbol count (%ld)"), - abfd->filename, + _bfd_error_handler + /* xgettext:c-format */ + (_("%B: version count (%ld) does not match symbol count (%ld)"), + abfd, (long) (verhdr->sh_size / sizeof (Elf_External_Versym)), symcount); @@ -1214,10 +1221,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) for (isym = isymbuf + 1, sym = symbase; isym < isymend; isym++, sym++) { memcpy (&sym->internal_elf_sym, isym, sizeof (Elf_Internal_Sym)); - sym->symbol.the_bfd = abfd; + sym->symbol.the_bfd = abfd; sym->symbol.name = bfd_elf_sym_name (abfd, hdr, isym, NULL); - sym->symbol.value = isym->st_value; if (isym->st_shndx == SHN_UNDEF) @@ -1300,6 +1306,7 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) case STT_COMMON: /* FIXME: Do we have to put the size field into the value field as we do with symbols in SHN_COMMON sections (see above) ? */ + sym->symbol.flags |= BSF_ELF_COMMON; /* Fall through. */ case STT_OBJECT: sym->symbol.flags |= BSF_OBJECT; @@ -1436,9 +1443,10 @@ elf_slurp_reloc_table_from_section (bfd *abfd, relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; else if (ELF_R_SYM (rela.r_info) > symcount) { - (*_bfd_error_handler) - (_("%s(%s): relocation %d has invalid symbol index %ld"), - abfd->filename, asect->name, i, ELF_R_SYM (rela.r_info)); + _bfd_error_handler + /* xgettext:c-format */ + (_("%B(%A): relocation %d has invalid symbol index %ld"), + abfd, asect, i, ELF_R_SYM (rela.r_info)); relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr; } else @@ -1501,7 +1509,9 @@ elf_slurp_reloc_table (bfd *abfd, rel_hdr2 = d->rela.hdr; reloc_count2 = rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0; - BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2); + /* PR 17512: file: 0b4f81b7. */ + if (asect->reloc_count != reloc_count + reloc_count2) + return FALSE; BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset) || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));