2017-02-17 17:48:50 +03:00
|
|
|
option(ENABLE_FUZZING "Create executables and targets for fuzzing cJSON with afl." Off)
|
|
|
|
if (ENABLE_FUZZING)
|
|
|
|
find_program(AFL_FUZZ afl-fuzz)
|
|
|
|
if ("${AFL_FUZZ}" MATCHES "AFL_FUZZ-NOTFOUND")
|
|
|
|
message(FATAL_ERROR "Couldn't find afl-fuzz.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_executable(afl-main afl.c)
|
|
|
|
target_link_libraries(afl-main "${CJSON_LIB}")
|
|
|
|
|
|
|
|
if (NOT ENABLE_SANITIZERS)
|
|
|
|
message(FATAL_ERROR "Enable sanitizers with -DENABLE_SANITIZERS=On to do fuzzing.")
|
|
|
|
endif()
|
|
|
|
|
2017-02-18 04:07:12 +03:00
|
|
|
option(ENABLE_FUZZING_PRINT "Fuzz printing functions together with parser." On)
|
|
|
|
set(fuzz_print_parameter "no")
|
|
|
|
if (ENABLE_FUZZING_PRINT)
|
|
|
|
set(fuzz_print_parameter "yes")
|
|
|
|
endif()
|
|
|
|
|
2017-02-18 04:52:38 +03:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
|
|
|
|
|
2017-02-17 17:48:50 +03:00
|
|
|
add_custom_target(afl
|
2017-02-18 04:07:12 +03:00
|
|
|
COMMAND "${AFL_FUZZ}" -i "${CMAKE_CURRENT_SOURCE_DIR}/inputs" -o "${CMAKE_CURRENT_BINARY_DIR}/findings" -x "${CMAKE_CURRENT_SOURCE_DIR}/json.dict" -- "${CMAKE_CURRENT_BINARY_DIR}/afl-main" "@@" "${fuzz_print_parameter}"
|
2017-02-17 17:48:50 +03:00
|
|
|
DEPENDS afl-main)
|
|
|
|
|
|
|
|
|
|
|
|
endif()
|
2019-08-24 18:42:48 +03:00
|
|
|
|
|
|
|
if(ENABLE_CJSON_TEST)
|
|
|
|
ADD_EXECUTABLE(fuzz_main fuzz_main.c)
|
|
|
|
TARGET_LINK_LIBRARIES(fuzz_main cjson)
|
|
|
|
endif()
|