mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-27 14:39:09 +08:00
Fix seg-fault reading a corrupt ELF binary.
PR binutils/21640 * elf.c (setup_group): Zero the group section pointer list after allocation so that loops can be caught. Check for NULL pointers when processing a group list.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2017-06-21 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
|
PR binutils/21640
|
||||||
|
* elf.c (setup_group): Zero the group section pointer list after
|
||||||
|
allocation so that loops can be caught. Check for NULL pointers
|
||||||
|
when processing a group list.
|
||||||
|
|
||||||
2017-06-19 H.J. Lu <hongjiu.lu@intel.com>
|
2017-06-19 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
PR ld/21626
|
PR ld/21626
|
||||||
|
14
bfd/elf.c
14
bfd/elf.c
@ -613,6 +613,7 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
|
|||||||
{
|
{
|
||||||
num_group = (unsigned) -1;
|
num_group = (unsigned) -1;
|
||||||
elf_tdata (abfd)->num_group = num_group;
|
elf_tdata (abfd)->num_group = num_group;
|
||||||
|
elf_tdata (abfd)->group_sect_ptr = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -625,8 +626,9 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
|
|||||||
bfd_alloc2 (abfd, num_group, sizeof (Elf_Internal_Shdr *));
|
bfd_alloc2 (abfd, num_group, sizeof (Elf_Internal_Shdr *));
|
||||||
if (elf_tdata (abfd)->group_sect_ptr == NULL)
|
if (elf_tdata (abfd)->group_sect_ptr == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
memset (elf_tdata (abfd)->group_sect_ptr, 0, num_group * sizeof (Elf_Internal_Shdr *));
|
||||||
num_group = 0;
|
num_group = 0;
|
||||||
|
|
||||||
for (i = 0; i < shnum; i++)
|
for (i = 0; i < shnum; i++)
|
||||||
{
|
{
|
||||||
Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i];
|
Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i];
|
||||||
@ -739,8 +741,14 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
|
|||||||
for (i = 0; i < num_group; i++)
|
for (i = 0; i < num_group; i++)
|
||||||
{
|
{
|
||||||
Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
|
Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
|
||||||
Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents;
|
Elf_Internal_Group *idx;
|
||||||
unsigned int n_elt = shdr->sh_size / 4;
|
unsigned int n_elt;
|
||||||
|
|
||||||
|
if (shdr == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
idx = (Elf_Internal_Group *) shdr->contents;
|
||||||
|
n_elt = shdr->sh_size / 4;
|
||||||
|
|
||||||
/* Look through this group's sections to see if current
|
/* Look through this group's sections to see if current
|
||||||
section is a member. */
|
section is a member. */
|
||||||
|
Reference in New Issue
Block a user