From 38d90c34378e0c6da2b2844255facaaa69e34f94 Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 2 Nov 2022 20:35:43 +0000 Subject: [PATCH] Fix missed judgment of sanity_check_range --- deps/oblib/src/lib/alloc/memory_sanity.cpp | 11 +++++++---- deps/oblib/src/lib/alloc/memory_sanity.h | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/deps/oblib/src/lib/alloc/memory_sanity.cpp b/deps/oblib/src/lib/alloc/memory_sanity.cpp index d1ddb6b1b2..1e1110593f 100644 --- a/deps/oblib/src/lib/alloc/memory_sanity.cpp +++ b/deps/oblib/src/lib/alloc/memory_sanity.cpp @@ -49,13 +49,16 @@ void sanity_set_whitelist(const char *str) void memory_sanity_abort() { + if ('\0' == whitelist[0]) { + abort(); + } void *addrs[128]; int n_addr = backtrace(addrs, sizeof(addrs)/sizeof(addrs[0])); void *vip_addr = NULL; for (int i = 0; NULL == vip_addr && i < n_addr; i++) { - for (int j = 0; NULL == vip_addr && j < 8; j++) { + for (int j = 0; NULL == vip_addr && j < sizeof(vips)/sizeof(vips[0]); j++) { t_vip *vip = &vips[j]; - if (0 == strlen(vip->func_)) { + if ('\0' == vip->func_[0]) { break; } else if (0 == vip->min_addr_ || 0 == vip->max_addr_) { continue; @@ -81,9 +84,9 @@ void memory_sanity_abort() if (real_len < buf_len - pos) { pos += real_len; } - for (int i = 0; i < 8; i++) { + for (int i = 0; i < sizeof(vips)/sizeof(vips[0]); i++) { t_vip *vip = &vips[i]; - if (0 == strlen(vip->func_)) { + if ('\0' == vip->func_[0]) { break; } else if (strstr(func_name, vip->func_) != NULL) { strncpy(vip_func, func_name, sizeof(vip_func)); diff --git a/deps/oblib/src/lib/alloc/memory_sanity.h b/deps/oblib/src/lib/alloc/memory_sanity.h index b8c1342234..774f17c84d 100644 --- a/deps/oblib/src/lib/alloc/memory_sanity.h +++ b/deps/oblib/src/lib/alloc/memory_sanity.h @@ -72,7 +72,7 @@ static constexpr int64_t sanity_max_canonical_addr = 0x4f210376cf1c; static inline bool sanity_addr_in_range(const void *ptr) { - return (int64_t)ptr >= sanity_min_canonical_addr && (int64_t)ptr < sanity_max_canonical_addr; + return (int64_t)ptr < sanity_max_canonical_addr && (int64_t)ptr >= sanity_min_canonical_addr; } static inline void* sanity_to_shadow(const void *ptr) @@ -139,12 +139,12 @@ static inline void sanity_check_range(const void *ptr, ssize_t len) char *start_align = (char*)sanity_align_up((uint64_t)start, 8); char *end_align = (char*)sanity_align_down((uint64_t)end, 8); if (start_align > start && - (*(uint8_t*)sanity_to_shadow(start_align - 8) != 0x0 && - *(uint8_t*)sanity_to_shadow(start_align - 8) < (len + start - (start_align - 8)))) { + (*(int8_t*)sanity_to_shadow(start_align - 8) != 0x0 && + *(int8_t*)sanity_to_shadow(start_align - 8) < (len + start - (start_align - 8)))) { memory_sanity_abort(); } if (end_align >= start_align + 8) { - if (*(uint8_t*)sanity_to_shadow(start_align) != 0x0) { + if (*(int8_t*)sanity_to_shadow(start_align) != 0x0) { memory_sanity_abort(); } if (end_align > start_align + 8) { @@ -157,8 +157,8 @@ static inline void sanity_check_range(const void *ptr, ssize_t len) } } if (end_align < end && - (*(uint8_t*)sanity_to_shadow(end_align) != 0x0 && - *(uint8_t*)sanity_to_shadow(end_align) < (end - end_align))) { + (*(int8_t*)sanity_to_shadow(end_align) != 0x0 && + *(int8_t*)sanity_to_shadow(end_align) < (end - end_align))) { memory_sanity_abort(); } }