Fix missed judgment of sanity_check_range

This commit is contained in:
obdev
2022-11-02 20:35:43 +00:00
committed by wangzelin.wzl
parent 5077661704
commit 38d90c3437
2 changed files with 13 additions and 10 deletions

View File

@ -49,13 +49,16 @@ void sanity_set_whitelist(const char *str)
void memory_sanity_abort() void memory_sanity_abort()
{ {
if ('\0' == whitelist[0]) {
abort();
}
void *addrs[128]; void *addrs[128];
int n_addr = backtrace(addrs, sizeof(addrs)/sizeof(addrs[0])); int n_addr = backtrace(addrs, sizeof(addrs)/sizeof(addrs[0]));
void *vip_addr = NULL; void *vip_addr = NULL;
for (int i = 0; NULL == vip_addr && i < n_addr; i++) { 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]; t_vip *vip = &vips[j];
if (0 == strlen(vip->func_)) { if ('\0' == vip->func_[0]) {
break; break;
} else if (0 == vip->min_addr_ || 0 == vip->max_addr_) { } else if (0 == vip->min_addr_ || 0 == vip->max_addr_) {
continue; continue;
@ -81,9 +84,9 @@ void memory_sanity_abort()
if (real_len < buf_len - pos) { if (real_len < buf_len - pos) {
pos += real_len; 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]; t_vip *vip = &vips[i];
if (0 == strlen(vip->func_)) { if ('\0' == vip->func_[0]) {
break; break;
} else if (strstr(func_name, vip->func_) != NULL) { } else if (strstr(func_name, vip->func_) != NULL) {
strncpy(vip_func, func_name, sizeof(vip_func)); strncpy(vip_func, func_name, sizeof(vip_func));

View File

@ -72,7 +72,7 @@ static constexpr int64_t sanity_max_canonical_addr = 0x4f210376cf1c;
static inline bool sanity_addr_in_range(const void *ptr) 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) 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 *start_align = (char*)sanity_align_up((uint64_t)start, 8);
char *end_align = (char*)sanity_align_down((uint64_t)end, 8); char *end_align = (char*)sanity_align_down((uint64_t)end, 8);
if (start_align > start && if (start_align > start &&
(*(uint8_t*)sanity_to_shadow(start_align - 8) != 0x0 && (*(int8_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) < (len + start - (start_align - 8)))) {
memory_sanity_abort(); memory_sanity_abort();
} }
if (end_align >= start_align + 8) { 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(); memory_sanity_abort();
} }
if (end_align > start_align + 8) { 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 && if (end_align < end &&
(*(uint8_t*)sanity_to_shadow(end_align) != 0x0 && (*(int8_t*)sanity_to_shadow(end_align) != 0x0 &&
*(uint8_t*)sanity_to_shadow(end_align) < (end - end_align))) { *(int8_t*)sanity_to_shadow(end_align) < (end - end_align))) {
memory_sanity_abort(); memory_sanity_abort();
} }
} }