]> git.ipfire.org Git - thirdparty/elfutils.git/blobdiff - libelf/elf_begin.c
libelf: Make sure we have at least a full ELF header available.
[thirdparty/elfutils.git] / libelf / elf_begin.c
index 43828c9a3ecf69cec472c6b51966a27f9de2db88..32648c153c0096cb7f1590304414e829509fdb77 100644 (file)
@@ -88,6 +88,13 @@ get_shnum (void *map_address, unsigned char *e_ident, int fildes,
   } 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