From 619aeb54ff673cd15aba257a05fe580c2a0b4af0 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Fri, 30 Dec 2022 10:29:25 -0800 Subject: [PATCH] Pesky "upx -t" mode https://github.com/upx/upx/issues/599 modified: p_lx_elf.cpp --- src/p_lx_elf.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index e3c7d0e2..30d260e1 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -4887,8 +4887,10 @@ PackLinuxElf64::unRela64( (void)old_dtinit; } // end each RELA - fo->seek(dt_rela, SEEK_SET); - fo->rewrite(rela0, relasz); + if (fo) { + fo->seek(dt_rela, SEEK_SET); + fo->rewrite(rela0, relasz); + } } // File layout of compressed .so (new-style: 3 or 4 PT_LOAD) shared library: @@ -5045,7 +5047,9 @@ void PackLinuxElf64::un_shlib_1( if (p_offset < yct_off) { p_offset = yct_off; // not at beginning of PT_LOAD } - fo->seek(p_offset, SEEK_SET); + if (fo) { + fo->seek(p_offset, SEEK_SET); + } // Peek at b_info to find sizes fi->readx(&hdr.b, sizeof(hdr.b)); fi->seek(-(off_t)sizeof(struct b_info), SEEK_CUR); @@ -5204,8 +5208,10 @@ void PackLinuxElf64::un_DT_INIT( upx_uint64_t d = plt_va - vaddr - asl_delta; if (d < filesz) { upx_uint64_t offset = get_te64(&phdr->p_offset); - fo->seek(d + offset, SEEK_SET); - fo->rewrite(jump_slots, n_plt * sizeof(upx_uint64_t)); + if (fo) { + fo->seek(d + offset, SEEK_SET); + fo->rewrite(jump_slots, n_plt * sizeof(upx_uint64_t)); + } break; } }