diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 7bee5828..fc2d0d91 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -212,6 +212,12 @@ PackLinuxElf32::PackLinuxElf32help1(InputFile *f) e_type = get_te16(&ehdri.e_type); e_phnum = get_te16(&ehdri.e_phnum); e_shnum = get_te16(&ehdri.e_shnum); + if (ehdri.e_ident[Elf32_Ehdr::EI_CLASS]!=Elf32_Ehdr::ELFCLASS32) { + e_phoff = 0; + e_shoff = 0; + sz_phdrs = 0; + return; + } e_phoff = get_te32(&ehdri.e_phoff); e_shoff = get_te32(&ehdri.e_shoff); sz_phdrs = e_phnum * get_te16(&ehdri.e_phentsize); @@ -567,6 +573,12 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f) e_type = get_te16(&ehdri.e_type); e_phnum = get_te16(&ehdri.e_phnum); e_shnum = get_te16(&ehdri.e_shnum); + if (ehdri.e_ident[Elf64_Ehdr::EI_CLASS]!=Elf64_Ehdr::ELFCLASS64) { + e_phoff = 0; + e_shoff = 0; + sz_phdrs = 0; + return; + } e_phoff = get_te64(&ehdri.e_phoff); e_shoff = get_te64(&ehdri.e_shoff); sz_phdrs = e_phnum * get_te16(&ehdri.e_phentsize); diff --git a/src/p_lx_elf.h b/src/p_lx_elf.h index 03bc575a..b22d5ca7 100644 --- a/src/p_lx_elf.h +++ b/src/p_lx_elf.h @@ -72,8 +72,6 @@ protected: unsigned e_type; unsigned e_phnum; /* Program header table entry count */ unsigned e_shnum; - unsigned e_phoff; - unsigned e_shoff; char *file_image; // if ET_DYN investigation char const *dynstr; // from DT_STRTAB @@ -153,6 +151,8 @@ protected: protected: Elf32_Ehdr ehdri; // from input file Elf32_Phdr *phdri; // for input file + unsigned e_phoff; + unsigned e_shoff; unsigned char *note_body; // concatenated contents of PT_NOTEs, if any unsigned note_size; // total size of PT_NOTEs Elf32_Shdr const *shdri; // from input file @@ -268,6 +268,8 @@ protected: protected: Elf64_Ehdr ehdri; // from input file Elf64_Phdr *phdri; // for input file + upx_uint64_t e_phoff; + upx_uint64_t e_shoff; unsigned char *note_body; // concatenated contents of PT_NOTEs, if any unsigned note_size; // total size of PT_NOTEs Elf64_Shdr const *shdri; // from input file