2022-02-24 00:00:53 +08:00
|
|
|
# Override network and random functions
|
2022-04-11 02:48:09 +08:00
|
|
|
add_library(fuzz_support func_conversion.h fuzz_support.cc fuzz_support.h)
|
2022-02-24 00:00:53 +08:00
|
|
|
|
|
|
|
set(LIBFUZZER_LINKER_FLAGS)
|
2024-01-11 23:24:02 +08:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2022-02-24 00:00:53 +08:00
|
|
|
set(LIBFUZZER_LINKER_FLAGS "-fsanitize=fuzzer")
|
|
|
|
else()
|
|
|
|
message(SEND_ERROR "Compiler must be Clang to build fuzz targets")
|
|
|
|
endif()
|
|
|
|
|
2024-01-11 23:24:02 +08:00
|
|
|
function(fuzz_test target source_dir)
|
2024-01-13 00:11:07 +08:00
|
|
|
set(CORPUS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/toktok-fuzzer/corpus/${target}_fuzz_test)
|
|
|
|
file(GLOB CORPUS "${CORPUS_DIR}/*")
|
2024-01-11 23:24:02 +08:00
|
|
|
add_executable(${target}_fuzz_test ${source_dir}/${target}_fuzz_test.cc)
|
2024-01-13 21:43:01 +08:00
|
|
|
target_link_libraries(${target}_fuzz_test PRIVATE fuzz_support test_util toxcore_fuzz ${LIBFUZZER_LINKER_FLAGS})
|
2024-01-13 00:11:07 +08:00
|
|
|
if(CORPUS)
|
|
|
|
add_test(NAME ${target}_fuzz COMMAND ${CROSSCOMPILING_EMULATOR} ${target}_fuzz_test -max_total_time=10 ${CORPUS})
|
|
|
|
set_property(TEST ${target}_fuzz PROPERTY ENVIRONMENT "LLVM_PROFILE_FILE=${target}.profraw;srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
|
2024-01-11 23:24:02 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2024-01-13 00:11:07 +08:00
|
|
|
fuzz_test(bootstrap .) # Fuzzes the bootstrap process
|
|
|
|
fuzz_test(toxsave .) # Fuzzes the bootstrap process
|
2022-03-28 02:24:47 +08:00
|
|
|
|
2024-01-11 23:24:02 +08:00
|
|
|
fuzz_test(DHT ../../toxcore)
|
|
|
|
fuzz_test(forwarding ../../toxcore)
|
|
|
|
fuzz_test(group_announce ../../toxcore)
|
|
|
|
fuzz_test(group_moderation ../../toxcore)
|
|
|
|
fuzz_test(tox_events ../../toxcore)
|