of the zeroth section. */
Elf_Scn *scn0 = &elf->state.ELFW(elf,LIBELFBITS).scns.data[0];
+ /* Make sure section zero header is actually loaded. */
+ if (scn0->shdr.ELFW(e,LIBELFBITS) == NULL)
+ (void) __elfw2(LIBELFBITS,getshdr_wrlock) (scn0);
+
update_if_changed (scn0->shdr.ELFW(e,LIBELFBITS)->sh_size,
shnum, scn0->shdr_flags);
}
exit (1);
}
- Elf *elf = elf_begin (fd, use_mmap ? ELF_C_READ_MMAP : ELF_C_READ, NULL);
+ Elf *elf = elf_begin (fd, use_mmap ? ELF_C_READ_MMAP_PRIVATE : ELF_C_READ,
+ NULL);
if (elf == NULL)
{
printf ("cannot create ELF descriptor: %s\n", elf_errmsg (-1));
exit (1);
}
+ /* Check if we can update the elf layout without having read anything.
+ This used to crash with 65280+ sections.
+ https://sourceware.org/bugzilla/show_bug.cgi?id=33967
+ Still crashes for read-only mmap.
+ https://sourceware.org/bugzilla/show_bug.cgi?id=33968
+ */
+ if (elf_update (elf, ELF_C_NULL) < 0)
+ {
+ printf ("failure in elf_update: %s\n", elf_errmsg (-1));
+ exit (1);
+ }
+
/* How many sections are there? */
size_t shnum;
if (elf_getshdrnum (elf, &shnum) < 0)