From: Nick Clifton Date: Tue, 18 Sep 2018 15:54:07 +0000 (+0100) Subject: Add a warning to the bfd library for when it encounters an ELF file with an invalid... X-Git-Tag: users/ARM/embedded-binutils-master-2018q4~691 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8ff71a9c80cfcf64c54d4ae938c644b1b1ea19fb;p=platform%2Fupstream%2Fbinutils.git Add a warning to the bfd library for when it encounters an ELF file with an invalid section size. PR 23657 * elfcode.h (elf_swap_shdr_in): Generate a warning message if an ELF section has contents and size larger than the file size. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 70de004..04c0c2a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2018-09-18 Nick Clifton + + PR 23657 + * elfcode.h (elf_swap_shdr_in): Generate a warning message if an + ELF section has contents and size larger than the file size. + 2018-09-14 Maciej W. Rozycki PR ld/21375 diff --git a/bfd/elfcode.h b/bfd/elfcode.h index fb02e25..f224c8b 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -314,6 +314,14 @@ elf_swap_shdr_in (bfd *abfd, dst->sh_addr = H_GET_WORD (abfd, src->sh_addr); dst->sh_offset = H_GET_WORD (abfd, src->sh_offset); dst->sh_size = H_GET_WORD (abfd, src->sh_size); + /* PR 23657. Check for invalid section size, in sections with contents. + Note - we do not set an error value here because the contents + of this particular section might not be needed by the consumer. */ + if (dst->sh_type != SHT_NOBITS + && dst->sh_size > bfd_get_file_size (abfd)) + _bfd_error_handler + (_("warning: %pB has a corrupt section with a size (%" BFD_VMA_FMT "x) larger than the file size"), + abfd, dst->sh_size); dst->sh_link = H_GET_32 (abfd, src->sh_link); dst->sh_info = H_GET_32 (abfd, src->sh_info); dst->sh_addralign = H_GET_WORD (abfd, src->sh_addralign);