aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2017-08-14 12:09:36 +0100
committerNick Clifton <nickc@redhat.com>2017-08-14 12:09:36 +0100
commit0c54f69295208331faab9bc5e995111a35672f9b (patch)
tree13717e998110407acae600f54ed7032ab901346b /bfd/elf.c
parentd7f00f429aa525816cb3895462113326b6cb2fe2 (diff)
downloadgdb-0c54f69295208331faab9bc5e995111a35672f9b.zip
gdb-0c54f69295208331faab9bc5e995111a35672f9b.tar.gz
gdb-0c54f69295208331faab9bc5e995111a35672f9b.tar.bz2
Fix null pointer dereference when parsing a corrupt ELF binary.
PR 21957 * elf.c (setup_group): Check for an empty or very small group section. * po/bfd.pot: Regenerate.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index d702474..2aa2337 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -742,12 +742,22 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
{
Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
Elf_Internal_Group *idx;
- unsigned int n_elt;
+ bfd_size_type n_elt;
if (shdr == NULL)
continue;
idx = (Elf_Internal_Group *) shdr->contents;
+ if (idx == NULL || shdr->sh_size < 4)
+ {
+ /* See PR 21957 for a reproducer. */
+ /* xgettext:c-format */
+ _bfd_error_handler (_("%B: group section '%A' has no contents"),
+ abfd, shdr->bfd_section);
+ elf_tdata (abfd)->group_sect_ptr[i] = NULL;
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
n_elt = shdr->sh_size / 4;
/* Look through this group's sections to see if current
@@ -801,7 +811,7 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
if (elf_group_name (newsect) == NULL)
{
/* xgettext:c-format */
- _bfd_error_handler (_("%B: no group info for section %A"),
+ _bfd_error_handler (_("%B: no group info for section '%A'"),
abfd, newsect);
return FALSE;
}