From 1bb0fa1809c781e1de9dcae8ee3e6089cf40f799 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 21 Sep 2016 00:35:51 +0200 Subject: [PATCH] Fix a few things spotted by the gcc-6 sanitizer. Needs review. --- src/linker.cpp | 3 ++- src/p_lx_elf.cpp | 6 ++++++ src/p_unix.cpp | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/linker.cpp b/src/linker.cpp index 9fcb5c98..3ddedb44 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -69,7 +69,8 @@ ElfLinker::Section::Section(const char *n, const void *i, unsigned s, unsigned a assert(name != NULL); input = malloc(s + 1); assert(input != NULL); - memcpy(input, i, s); + if (s != 0) + memcpy(input, i, s); ((char *)input)[s] = 0; } diff --git a/src/p_lx_elf.cpp b/src/p_lx_elf.cpp index 39e711be..afb74677 100644 --- a/src/p_lx_elf.cpp +++ b/src/p_lx_elf.cpp @@ -230,6 +230,7 @@ PackLinuxElf32::PackLinuxElf32help1(InputFile *f) if (f && Elf32_Ehdr::ET_DYN!=e_type) { unsigned const len = sz_phdrs + e_phoff; + assert(file_image == NULL); file_image = New(char, len); f->seek(0, SEEK_SET); f->readx(file_image, len); @@ -237,6 +238,7 @@ PackLinuxElf32::PackLinuxElf32help1(InputFile *f) } if (f && Elf32_Ehdr::ET_DYN==e_type) { // The DT_STRTAB has no designated length. Read the whole file. + assert(file_image == NULL); file_image = New(char, file_size); f->seek(0, SEEK_SET); f->readx(file_image, file_size); @@ -600,6 +602,7 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f) if (f && Elf64_Ehdr::ET_DYN!=e_type) { unsigned const len = sz_phdrs + e_phoff; + assert(file_image == NULL); file_image = New(char, len); f->seek(0, SEEK_SET); f->readx(file_image, len); @@ -607,6 +610,7 @@ PackLinuxElf64::PackLinuxElf64help1(InputFile *f) } if (f && Elf64_Ehdr::ET_DYN==e_type) { // The DT_STRTAB has no designated length. Read the whole file. + assert(file_image == NULL); file_image = New(char, file_size); f->seek(0, SEEK_SET); f->readx(file_image, file_size); @@ -1662,6 +1666,7 @@ PackLinuxElf64ppcle::canPack() if (Elf32_Ehdr::ET_DYN==get_te16(&ehdr->e_type)) { // The DT_STRTAB has no designated length. Read the whole file. + assert(file_image == NULL); file_image = New(char, file_size); fi->seek(0, SEEK_SET); fi->readx(file_image, file_size); @@ -1837,6 +1842,7 @@ PackLinuxElf64amd::canPack() if (Elf32_Ehdr::ET_DYN==get_te16(&ehdr->e_type)) { // The DT_STRTAB has no designated length. Read the whole file. + assert(file_image == NULL); file_image = New(char, file_size); fi->seek(0, SEEK_SET); fi->readx(file_image, file_size); diff --git a/src/p_unix.cpp b/src/p_unix.cpp index 9c6fd5c2..a12f7863 100644 --- a/src/p_unix.cpp +++ b/src/p_unix.cpp @@ -325,7 +325,7 @@ void PackUnix::packExtent( } fi->seek(x.offset, SEEK_SET); for (off_t rest = x.size; 0 != rest; ) { - int const filter_strategy = getStrategy(*ft); + int const filter_strategy = ft ? getStrategy(*ft) : 0; int l = fi->readx(ibuf, UPX_MIN(rest, (off_t)blocksize)); if (l == 0) { break;