When elf_memory is called we could get a slightly too small image
that doesn't contain a full ELF header (but does contain at least
the e_ident values). Require the full header before even validating
the rest of the ELF header fields.
https://sourceware.org/bugzilla/show_bug.cgi?id=27076
Signed-off-by: Mark Wielaard <mark@klomp.org>
+2020-12-15 Mark Wielaard <mark@klomp.org>
+
+ * elf_begin.c (get_shnum): Make sure the full Ehdr is available.
+
2020-12-12 Dmitry V. Levin <ldv@altlinux.org>
* common.h: Fix spelling typo in comment.
} ehdr_mem;
bool is32 = e_ident[EI_CLASS] == ELFCLASS32;
+ if ((is32 && maxsize < sizeof (Elf32_Ehdr))
+ || (!is32 && maxsize < sizeof (Elf64_Ehdr)))
+ {
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return (size_t) -1l;
+ }
+
/* Make the ELF header available. */
if (e_ident[EI_DATA] == MY_ELFDATA
&& (ALLOW_UNALIGNED