Ensure that the file is bigger than an ELF header.
authorMartin Pieuchot <mpi@openbsd.org>
Thu, 10 Nov 2016 13:27:45 +0000 (14:27 +0100)
committerMartin Pieuchot <mpi@openbsd.org>
Thu, 10 Nov 2016 13:27:45 +0000 (14:27 +0100)
From tedu@

elf.c

diff --git a/elf.c b/elf.c
index 7f2da180ff924d80cbc3225ce14509930a213dff..565476ff3fb8cf380bfccd6671c2226f36de685a 100644 (file)
--- a/elf.c
+++ b/elf.c
@@ -25,6 +25,9 @@ iself(const char *p, size_t filesize)
 {
        Elf_Ehdr                *eh = (Elf_Ehdr *)p;
 
+       if (filesize < sizeof(Elf_Ehdr))
+               return 0;
+
        if (eh->e_ehsize < sizeof(Elf_Ehdr) || !IS_ELF(*eh))
                return 0;