From b526eed346f803665337b1e709c37458949964e6 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 23 Aug 2023 07:52:29 -0700 Subject: [PATCH] Detect "no Shdrs" earlier when already packed https://github.com/upx/upx/issues/699 modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 4f547176..d0d0484f 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -1046,12 +1046,15 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f) if (!(opt->cmd == CMD_COMPRESS && e_shoff < (upx_uint64_t)file_size && mb_shdr.getSize() == 0)) { shdri = nullptr; } - else { + else if (e_shnum && e_shoff && ehdri.e_shentsize) { fi->seek(e_shoff, SEEK_SET); mb_shdr.alloc( sizeof(Elf64_Shdr) * e_shnum); shdri = (Elf64_Shdr *)mb_shdr.getVoidPtr(); fi->readx(shdri, sizeof(Elf64_Shdr) * e_shnum); } + else { + shdri = nullptr; + } sec_dynsym = elf_find_section_type(Elf64_Shdr::SHT_DYNSYM); if (sec_dynsym) { unsigned t = get_te32(&sec_dynsym->sh_link);