From 11ee8627b8a8082ceaf2d7e928a83a5e4f46516b Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Fri, 29 Dec 2000 14:13:59 +0000 Subject: [PATCH] Improved some ELF header checks. committer: mfx 978099239 +0000 --- src/p_lx_elf.cpp | 5 ++++- src/p_lx_exc.cpp | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index a237794a..eea5540a 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -183,8 +183,11 @@ bool PackLinuxI386elf::canPack() if (j >= 14) return false; if (phdr->PT_LOAD == phdr->p_type) { - if (phdr->p_offset!=0) + if (phdr->p_offset != 0) + { + throwCantPack("invalid Phdr p_offset; try `--force-execve'"); return false; + } exetype = 1; break; } diff --git a/src/p_lx_exc.cpp b/src/p_lx_exc.cpp index a56a8157..941e5f4a 100644 --- a/src/p_lx_exc.cpp +++ b/src/p_lx_exc.cpp @@ -95,11 +95,10 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const { const unsigned char * const buf = ehdr->e_ident; - // NOTE: ELF executables are now handled by p_lx_elf.cpp. + // info: ELF executables are now handled by p_lx_elf.cpp if (memcmp(buf, "\x7f\x45\x4c\x46\x01\x01\x01", 7)) // ELF 32-bit LSB return -1; - // FIXME: add special checks for uncompresed "vmlinux" kernel // now check the ELF header if (!memcmp(buf+8, "FreeBSD", 7)) // branded return 1; @@ -109,6 +108,12 @@ int PackLinuxI386::checkEhdr(const Elf_LE32_Ehdr *ehdr) const return 3; if (ehdr->e_version != 1) // version return 4; + if (ehdr->e_phnum < 1) + return 5; + + // FIXME: add special checks for uncompresed "vmlinux" kernel + // FIXME: add special checks for other ELF i386 formats, like + // NetBSD, OpenBSD, Solaris, .... // success return 0;