aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2015-08-11 11:57:09 +0100
committerNick Clifton <nickc@redhat.com>2015-08-11 11:57:09 +0100
commit4b0e8a5f80441fad8eddaf68e7af70bd6991aa37 (patch)
treeff5f7482114d200ce52b6094c721df98dc2478ad /bfd/elf.c
parent64140f86ab732f9ed87beccab07c32befaf9ca52 (diff)
downloadgdb-4b0e8a5f80441fad8eddaf68e7af70bd6991aa37.zip
gdb-4b0e8a5f80441fad8eddaf68e7af70bd6991aa37.tar.gz
gdb-4b0e8a5f80441fad8eddaf68e7af70bd6991aa37.tar.bz2
Fix memory access problems discovered when running some binary tools on corrupt files.
PR binutils/18758 * elf.c (_bfd_elf_setup_sections): Add checks for corrupt section group information. * peicode.h (pe_ILF_make_a_section): Ensure alignment of the used_by_bfd pointer. (pe_ILF_build_a_bfd): Ensure alignment of vars.data pointer.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 15de37b..7ae2e34 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -817,9 +817,22 @@ _bfd_elf_setup_sections (bfd *abfd)
for (i = 0; i < num_group; i++)
{
Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
- Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents;
- unsigned int n_elt = shdr->sh_size / 4;
+ Elf_Internal_Group *idx;
+ unsigned int n_elt;
+ /* PR binutils/18758: Beware of corrupt binaries with invalid group data. */
+ if (shdr == NULL || shdr->bfd_section == NULL || shdr->contents == NULL)
+ {
+ (*_bfd_error_handler)
+ (_("%B: section group entry number %u is corrupt"),
+ abfd, i);
+ result = FALSE;
+ continue;
+ }
+
+ idx = (Elf_Internal_Group *) shdr->contents;
+ n_elt = shdr->sh_size / 4;
+
while (--n_elt != 0)
if ((++idx)->shdr->bfd_section)
elf_sec_group (idx->shdr->bfd_section) = shdr->bfd_section;