diff --git a/src/conf.h b/src/conf.h index c5f82113..9d8befda 100644 --- a/src/conf.h +++ b/src/conf.h @@ -472,7 +472,7 @@ struct upx_callback_t template struct OptVar { - typedef T Type; + typedef T value_type; static const T default_value_c = default_value; static const T min_value_c = min_value; static const T max_value_c = max_value; diff --git a/src/file.cpp b/src/file.cpp index b6042017..0f93956e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -170,7 +170,7 @@ void FileBase::write(const void *buf, int len) off_t FileBase::seek(upx_int64_t off64, int whence) { - (void) mem_size(1, off64 >= 0 ? off64 : -off64); // sanity check + mem_size_assert(1, off64 >= 0 ? off64 : -off64); // sanity check off_t off = ACC_ICONV(off_t, off64); if (!isOpen()) throwIOException("bad seek 1"); @@ -406,7 +406,7 @@ void OutputFile::rewrite(const void *buf, int len) off_t OutputFile::seek(upx_int64_t off64, int whence) { - (void) mem_size(1, off64 >= 0 ? off64 : -off64); // sanity check + mem_size_assert(1, off64 >= 0 ? off64 : -off64); // sanity check off_t off = ACC_ICONV(off_t, off64); assert(!opt->to_stdout); switch (whence) { diff --git a/src/mem.cpp b/src/mem.cpp index 15f5af15..84721e2f 100644 --- a/src/mem.cpp +++ b/src/mem.cpp @@ -52,7 +52,7 @@ size_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra) size_t mem_size_get_n(upx_uint64_t element_size, upx_uint64_t n) { - (void) mem_size(element_size, n); // check + mem_size_assert(element_size, n); return ACC_ICONV(size_t, n); // return n } @@ -90,29 +90,29 @@ int ptr_diff(const char *p1, const char *p2) /************************************************************************* -// bool use_mcheck() +// bool use_simple_mcheck() **************************************************************************/ #if defined(__SANITIZE_ADDRESS__) -__acc_static_forceinline bool use_mcheck() { return false; } +__acc_static_forceinline bool use_simple_mcheck() { return false; } #elif (WITH_VALGRIND) && defined(RUNNING_ON_VALGRIND) -static int use_mcheck_flag = -1; -__acc_static_noinline void use_mcheck_init() +static int use_simple_mcheck_flag = -1; +__acc_static_noinline void use_simple_mcheck_init() { - use_mcheck_flag = 1; + use_simple_mcheck_flag = 1; if (RUNNING_ON_VALGRIND) { - use_mcheck_flag = 0; + use_simple_mcheck_flag = 0; //fprintf(stderr, "upx: detected RUNNING_ON_VALGRIND\n"); } } -__acc_static_forceinline bool use_mcheck() +__acc_static_forceinline bool use_simple_mcheck() { - if __acc_unlikely(use_mcheck_flag < 0) - use_mcheck_init(); - return (bool) use_mcheck_flag; + if __acc_unlikely(use_simple_mcheck_flag < 0) + use_simple_mcheck_init(); + return (bool) use_simple_mcheck_flag; } #else -__acc_static_forceinline bool use_mcheck() { return true; } +__acc_static_forceinline bool use_simple_mcheck() { return true; } #endif @@ -137,7 +137,7 @@ void MemBuffer::dealloc() if (b != NULL) { checkState(); - if (use_mcheck()) + if (use_simple_mcheck()) { // remove magic constants set_be32(b - 8, 0); @@ -217,7 +217,7 @@ void MemBuffer::checkState() const { if (!b) throwInternalError("block not allocated"); - if (use_mcheck()) + if (use_simple_mcheck()) { if (get_be32(b - 4) != MAGIC1(b)) throwInternalError("memory clobbered before allocated block 1"); @@ -237,12 +237,12 @@ void MemBuffer::alloc(upx_uint64_t size) assert(b_size == 0); // assert(size > 0); - size_t bytes = mem_size(1, size, use_mcheck() ? 32 : 0); + size_t bytes = mem_size(1, size, use_simple_mcheck() ? 32 : 0); unsigned char *p = (unsigned char *) malloc(bytes); if (!p) throwOutOfMemoryException(); b_size = ACC_ICONV(unsigned, size); - if (use_mcheck()) + if (use_simple_mcheck()) { b = p + 16; // store magic constants to detect buffer overruns diff --git a/src/util.h b/src/util.h index 648f3b49..9d8aff74 100644 --- a/src/util.h +++ b/src/util.h @@ -63,6 +63,10 @@ int mem_replace(void *b, int blen, const void *what, int wlen, const void *r); size_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0); size_t mem_size_get_n(upx_uint64_t element_size, upx_uint64_t n); +inline void mem_size_assert(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0) { + (void) mem_size(element_size, n, extra); // sanity check +} + bool mem_size_valid(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0); bool mem_size_valid_bytes(upx_uint64_t bytes);