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.
This commit is contained in:
Nick Clifton 2018-09-18 16:54:07 +01:00
parent 3ff2c72e14
commit 8ff71a9c80
2 changed files with 14 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2018-09-18 Nick Clifton <nickc@redhat.com>
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 <macro@mips.com>
PR ld/21375

View File

@ -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);