From 774c8c3fd4d73f2090850ca1cfb247e11c62ff22 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Wed, 25 Apr 2018 23:05:17 -0700 Subject: [PATCH] Fix forgotten get_teXX() in canPack() and invert_pt_dynamic() https://github.com/upx/upx/issues/200 modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 75b8f4e3..2645cf69 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -1548,10 +1548,11 @@ PackLinuxElf32::invert_pt_dynamic(Elf32_Dyn const *dynp) unsigned ndx = 1+ 0; if (dynp) for (; ; ++ndx, ++dynp) { - if (dynp->d_tag < DT_NUM) { - dt_table[dynp->d_tag] = ndx; + unsigned const d_tag = get_te32(&dynp->d_tag); + if (d_tag < DT_NUM) { + dt_table[d_tag] = ndx; } - if (Elf32_Dyn::DT_NULL == dynp->d_tag) { + if (Elf32_Dyn::DT_NULL == d_tag) { break; // check here so that dt_table[DT_NULL] is set } } @@ -1873,7 +1874,7 @@ bool PackLinuxElf32::canPack() if ((Elf32_Dyn::DT_INIT==upx_dt_init || !upx_dt_init) && Elf32_Shdr::SHT_DYNAMIC == sh_type) { unsigned const n = get_te32(&shdr->sh_size) / sizeof(Elf32_Dyn); - Elf32_Dyn *dynp = (Elf32_Dyn *)&file_image[shdr->sh_offset]; + Elf32_Dyn *dynp = (Elf32_Dyn *)&file_image[get_te32(&shdr->sh_offset)]; for (; Elf32_Dyn::DT_NULL != dynp->d_tag; ++dynp) { if (upx_dt_init == get_te32(&dynp->d_tag)) { break; // re-found DT_INIT @@ -2100,7 +2101,7 @@ PackLinuxElf64::canPack() if ((Elf64_Dyn::DT_INIT==upx_dt_init || !upx_dt_init) && Elf64_Shdr::SHT_DYNAMIC == sh_type) { unsigned const n = get_te64(&shdr->sh_size) / sizeof(Elf64_Dyn); - Elf64_Dyn *dynp = (Elf64_Dyn *)&file_image[shdr->sh_offset]; + Elf64_Dyn *dynp = (Elf64_Dyn *)&file_image[get_te64(&shdr->sh_offset)]; for (; Elf64_Dyn::DT_NULL != dynp->d_tag; ++dynp) { if (upx_dt_init == get_te64(&dynp->d_tag)) { break; // re-found DT_INIT @@ -4408,10 +4409,11 @@ PackLinuxElf64::invert_pt_dynamic(Elf64_Dyn const *dynp) unsigned ndx = 1+ 0; if (dynp) for (; ; ++ndx, ++dynp) { - if (dynp->d_tag < DT_NUM) { - dt_table[dynp->d_tag] = ndx; + upx_uint64_t const d_tag = get_te64(&dynp->d_tag); + if (d_tag < DT_NUM) { + dt_table[d_tag] = ndx; } - if (Elf64_Dyn::DT_NULL == dynp->d_tag) { + if (Elf64_Dyn::DT_NULL == d_tag) { break; // check here so that dt_table[DT_NULL] is set } }