Solve the problem that the sanity_check_range does not take effect when the length overflows
This commit is contained in:
7
deps/oblib/src/lib/alloc/memory_sanity.cpp
vendored
7
deps/oblib/src/lib/alloc/memory_sanity.cpp
vendored
@ -14,7 +14,6 @@
|
||||
#else
|
||||
#include "lib/alloc/memory_sanity.h"
|
||||
#include "lib/utility/utility.h"
|
||||
#include "objit/ob_llvm_symbolizer.h"
|
||||
|
||||
__thread bool enable_sanity_check = true;
|
||||
struct t_vip {
|
||||
@ -47,6 +46,8 @@ void sanity_set_whitelist(const char *str)
|
||||
}
|
||||
}
|
||||
|
||||
BacktraceSymbolizeFunc backtrace_symbolize_func = NULL;
|
||||
|
||||
void memory_sanity_abort()
|
||||
{
|
||||
if ('\0' == whitelist[0]) {
|
||||
@ -101,7 +102,9 @@ void memory_sanity_abort()
|
||||
}
|
||||
}
|
||||
};
|
||||
oceanbase::common::backtrace_symbolize(addrs, n_addr, check_vip);
|
||||
if (backtrace_symbolize_func != NULL) {
|
||||
backtrace_symbolize_func(addrs, n_addr, check_vip);
|
||||
}
|
||||
while (pos > 0 && '\n' == buf[pos - 1]) pos--;
|
||||
fprintf(stderr, "[ERROR] sanity check failed, vip_func: %s, lbt: %s\nsymbolize:\n%.*s\n", vip_func,
|
||||
oceanbase::common::parray((int64_t*)addrs, n_addr), pos, buf);
|
||||
|
||||
6
deps/oblib/src/lib/alloc/memory_sanity.h
vendored
6
deps/oblib/src/lib/alloc/memory_sanity.h
vendored
@ -134,10 +134,11 @@ static inline uint64_t sanity_align_up(uint64_t x, uint64_t align)
|
||||
static inline void sanity_check_range(const void *ptr, ssize_t len)
|
||||
{
|
||||
if (!enable_sanity_check) return;
|
||||
if (len <= 0) return;
|
||||
if (0 == len) return;
|
||||
if (!sanity_addr_in_range(ptr)) return;
|
||||
char *start = (char*)ptr;
|
||||
char *end = start + len;
|
||||
if (end <= start) memory_sanity_abort();
|
||||
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 &&
|
||||
@ -166,6 +167,9 @@ static inline void sanity_check_range(const void *ptr, ssize_t len)
|
||||
}
|
||||
|
||||
extern void sanity_set_whitelist(const char *str);
|
||||
using SymbolizeCb = std::function<void(void *, const char *, const char *, uint32_t)>;
|
||||
typedef int (*BacktraceSymbolizeFunc)(void **addrs, int32_t n_addr, SymbolizeCb cb);
|
||||
extern BacktraceSymbolizeFunc backtrace_symbolize_func;
|
||||
|
||||
#endif /* ENABLE_SANITY */
|
||||
#endif /* _MEMORY_SANITY_H_ */
|
||||
|
||||
2
deps/oblib/unittest/CMakeLists.txt
vendored
2
deps/oblib/unittest/CMakeLists.txt
vendored
@ -8,7 +8,7 @@ function(oblib_addtest mainfile)
|
||||
get_filename_component(testname ${mainfile} NAME_WE)
|
||||
add_executable(${testname} ${ARGV})
|
||||
add_test(${testname} ${testname})
|
||||
target_link_libraries(${testname} PRIVATE objit oblib oblib_testbase -static-libgcc -static-libstdc++
|
||||
target_link_libraries(${testname} PRIVATE oblib oblib_testbase -static-libgcc -static-libstdc++
|
||||
${OB_RELRO_FLAG} -Wl,-T,${CMAKE_SOURCE_DIR}/rpm/ld.lds)
|
||||
endfunction()
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "lib/allocator/ob_libeasy_mem_pool.h"
|
||||
#include "lib/signal/ob_signal_struct.h"
|
||||
#include "lib/utility/ob_defer.h"
|
||||
#include "objit/ob_llvm_symbolizer.h"
|
||||
#include "observer/ob_server.h"
|
||||
#include "observer/ob_server_struct.h"
|
||||
#include "observer/ob_server_utils.h"
|
||||
@ -435,6 +436,9 @@ void reasy_pool_set_allocator(reasy_pool_realloc_pt alloc);
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef ENABLE_SANITY
|
||||
backtrace_symbolize_func = oceanbase::common::backtrace_symbolize;
|
||||
#endif
|
||||
if (0 != pthread_getname_np(pthread_self(), ob_get_tname(), OB_THREAD_NAME_BUF_LEN)) {
|
||||
snprintf(ob_get_tname(), OB_THREAD_NAME_BUF_LEN, "observer");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user