diff --git a/.github/workflows/CITest.yml b/.github/workflows/CITest.yml index b4da67c8d2..fff2bbf44f 100644 --- a/.github/workflows/CITest.yml +++ b/.github/workflows/CITest.yml @@ -36,6 +36,7 @@ jobs: python-arch: x64, python-version: '3.6', build-system: 'cmake', + enable-asan: 'OFF' } - { name: 'ubuntu-22.04 x64 python3.9 make', @@ -44,6 +45,7 @@ jobs: python-arch: x64, python-version: '3.9', build-system: 'make', + enable-asan: 'OFF' } - { name: 'ubuntu-22.04 x64 python3.9 cmake', @@ -52,6 +54,7 @@ jobs: python-arch: x64, python-version: '3.9', build-system: 'cmake', + enable-asan: 'OFF' } - { name: 'ubuntu-22.04 x64 python3.11 cmake', @@ -60,6 +63,16 @@ jobs: python-arch: x64, python-version: '3.11', build-system: 'cmake', + enable-asan: 'OFF' + } + - { + name: 'ubuntu-22.04 x64 python3.11 ASAN', + os: ubuntu-22.04, + arch: x64, + python-arch: x64, + python-version: '3.11', + build-system: 'cmake', + enable-asan: 'ON' } steps: @@ -88,13 +101,15 @@ jobs: - name: cmake if: startsWith(matrix.config.build-system, 'cmake') + env: + asan: ${{ matrix.config.enable-asan }} run: | mkdir build && cd build # build static library cmake -DCAPSTONE_INSTALL=1 -DCMAKE_INSTALL_PREFIX=/usr .. cmake --build . --config Release # build shared library - cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr .. + cmake -DCAPSTONE_INSTALL=1 -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_ASAN=${asan} .. sudo cmake --build . --config Release --target install cp libcapstone.* ../ cp libcapstone.* ../tests/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a01ae8b6b..bd2623d789 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,13 @@ option(CAPSTONE_USE_ARCH_REGISTRATION "Use explicit architecture registration" O option(CAPSTONE_ARCHITECTURE_DEFAULT "Whether architectures are enabled by default" ON) option(CAPSTONE_DEBUG "Whether to enable extra debug assertions" OFF) option(CAPSTONE_INSTALL "Generate install target" ${PROJECT_IS_TOP_LEVEL}) +option(ENABLE_ASAN "Enable address sanitizer" OFF) + +if (ENABLE_ASAN) + add_definitions(-DASAN_ENABLED) + add_compile_options(-fsanitize=address) + add_link_options(-fsanitize=address) +endif() # If building for OSX it's best to allow CMake to handle building both architectures if(APPLE AND NOT CAPSTONE_BUILD_MACOS_THIN) diff --git a/COMPILE_CMAKE.TXT b/COMPILE_CMAKE.TXT index dfe491f966..7b9d64baae 100644 --- a/COMPILE_CMAKE.TXT +++ b/COMPILE_CMAKE.TXT @@ -56,6 +56,7 @@ Get CMake for free from http://www.cmake.org. - CAPSTONE_X86_REDUCE: change this to ON to make X86 binary smaller. - CAPSTONE_X86_ATT_DISABLE: change this to ON to disable AT&T syntax on x86. - CAPSTONE_DEBUG: change this to ON to enable extra debug assertions. + - ENABLE_ASAN: Compiles Capstone with the address sanitizer. By default, Capstone use system dynamic memory management, and both DIET and X86_REDUCE modes are disabled. To use your own memory allocations, turn ON both DIET &