@@ -39,6 +39,7 @@ option(S2N_INTEG_TESTS "Enable the integrationv2 tests" OFF)
39
39
option (S2N_FAST_INTEG_TESTS "Enable the integrationv2 with more parallelism, only has effect if S2N_INTEG_TESTS=ON" OFF )
40
40
option (S2N_INSTALL_S2NC_S2ND "Install the binaries s2nc and s2nd" OFF )
41
41
option (TSAN "Enable ThreadSanitizer to test thread safety" OFF )
42
+ option (ASAN "Enable AddressSanitizer to test memory safety" OFF )
42
43
43
44
# Turn BUILD_TESTING=ON by default
44
45
include (CTest)
@@ -218,6 +219,16 @@ if(TSAN)
218
219
target_link_options (${PROJECT_NAME} PUBLIC -fsanitize=thread)
219
220
endif ()
220
221
222
+ if (ASAN)
223
+ target_compile_options (${PROJECT_NAME} PUBLIC -fsanitize=address -DS2N_ADDRESS_SANITIZER=1)
224
+ target_link_options (${PROJECT_NAME} PUBLIC -fsanitize=address)
225
+ endif ()
226
+
227
+ if (TSAN OR ASAN)
228
+ # no-omit-frame-pointer and no-optimize-sibling-calls provide better stack traces
229
+ target_compile_options (${PROJECT_NAME} PUBLIC -fno-omit-frame-pointer -fno-optimize-sibling-calls)
230
+ endif ()
231
+
221
232
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake/modules" )
222
233
223
234
if (NOT $ENV{S2N_LIBCRYPTO} MATCHES "awslc" )
@@ -503,12 +514,14 @@ if (BUILD_TESTING)
503
514
add_library (allocator_overrides SHARED ${TEST_LD_PRELOAD} )
504
515
505
516
set (UNIT_TEST_ENVS S2N_DONT_MLOCK=1)
517
+ if (TSAN OR ASAN)
518
+ set (UNIT_TEST_ENVS ${UNIT_TEST_ENVS} S2N_ADDRESS_SANITIZER=1)
519
+ endif ()
506
520
if (TSAN)
507
521
set (TSAN_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR} /tests/.tsan_suppressions)
508
522
if (NOT EXISTS ${TSAN_SUPPRESSIONS_FILE} )
509
523
message (FATAL_ERROR "TSAN suppression file ${TSAN_SUPPRESSIONS_FILE} missing" )
510
524
endif ()
511
- set (UNIT_TEST_ENVS ${UNIT_TEST_ENVS} S2N_ADDRESS_SANITIZER=1)
512
525
set (TSAN_OPTIONS suppressions=${TSAN_SUPPRESSIONS_FILE} )
513
526
if (DEFINED ENV{TSAN_OPTIONS})
514
527
set (TSAN_OPTIONS "${TSAN_OPTIONS} $ENV{TSAN_OPTIONS} " )
0 commit comments