Add support for sanitizers and fix a crash
This commit is contained in:
parent
dced055689
commit
dc3a12bb50
|
|
@ -1,3 +1,48 @@
|
|||
option(ENABLE_SANITIZERS "Enable sanitizers" OFF)
|
||||
if(ENABLE_SANITIZERS)
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")
|
||||
# NOTE: There is bug in Clang-CL that makes address sanitizers not work for all projects.
|
||||
# The main issue is the 'world' project, which has WINDOWS_EXPORT_ALL_SYMBOLS.
|
||||
# This issue will likely be fixed in a later version of Clang-CL, but for now you should
|
||||
# configure with -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe to enable
|
||||
# UB sanitizers.
|
||||
message(WARNING "Enabling Clang-CL sanitizers (Clang works better)...")
|
||||
add_compile_options(-fsanitize=address,undefined)
|
||||
|
||||
# Reference: https://devblogs.microsoft.com/cppblog/addresssanitizer-asan-for-windows-with-msvc/
|
||||
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
|
||||
set(ASAN_LIB_SUFFIX "x86_64")
|
||||
else()
|
||||
set(ASAN_LIB_SUFFIX "i386")
|
||||
endif()
|
||||
set(ASAN_LINKER_FLAGS "/wholearchive:clang_rt.asan-${ASAN_LIB_SUFFIX}.lib /wholearchive:clang_rt.asan_cxx-${ASAN_LIB_SUFFIX}.lib")
|
||||
else()
|
||||
message(STATUS "Enabling Clang sanitizers...")
|
||||
add_compile_options(-fsanitize=address,undefined -fno-omit-frame-pointer)
|
||||
set(ASAN_LINKER_FLAGS "-fsanitize=address,undefined")
|
||||
endif()
|
||||
|
||||
# NOTE: Only set linker flags for executables and shared libraries
|
||||
# the add_link_options command would add flags to static libraries as well
|
||||
# which causes issues with symbols being defined in multiple places.
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${ASAN_LINKER_FLAGS}")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${ASAN_LINKER_FLAGS}")
|
||||
|
||||
if(WIN32)
|
||||
# NOTE: The sanitizer library only supports the static release runtime
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
|
||||
endif()
|
||||
elseif(MSVC)
|
||||
# Reference: https://learn.microsoft.com/en-us/cpp/build/reference/fsanitize
|
||||
message(WARNING "Enabling MSVC sanitizers (Clang has better support)...")
|
||||
add_compile_options(/fsanitize=address)
|
||||
add_link_options(/INCREMENTAL:NO)
|
||||
else()
|
||||
message (FATAL_ERROR "Unsupported compiler for sanitizers: ${CMAKE_CXX_COMPILER_ID}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Visual Studio generator specific flags
|
||||
if (CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
# HACK: DO NOT this to add compiler flags/definitions, use target_compile_options on a
|
||||
|
|
|
|||
|
|
@ -418,10 +418,9 @@ extern "C" __declspec(dllexport) bool isunicodestring(const unsigned char* data,
|
|||
|
||||
bool disasmispossiblestring(duint addr, STRING_TYPE* type)
|
||||
{
|
||||
unsigned char data[60];
|
||||
memset(data, 0, sizeof(data));
|
||||
unsigned char data[60] = {};
|
||||
duint bytesRead = 0;
|
||||
if(!MemReadUnsafe(addr, data, sizeof(data), &bytesRead) && bytesRead < 2)
|
||||
if(!MemReadUnsafe(addr, data, sizeof(data) - 1, &bytesRead) && bytesRead < 2)
|
||||
return false;
|
||||
if(isasciistring(data, sizeof(data)))
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue