2023-07-25 11:53:09 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
COMMON_CMAKE_OPTIONS="-DCMAKE_C_COMPILER=afl-clang-lto -DCMAKE_CXX_COMPILER=afl-clang-lto++ -DBUILD_TOXAV=OFF -DENABLE_SHARED=NO -DBUILD_FUZZ_TESTS=ON -DDHT_BOOTSTRAP=OFF -DBOOTSTRAP_DAEMON=OFF"
|
|
|
|
|
|
|
|
# move to repo root
|
|
|
|
cd ../
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target UBSAN
|
2023-07-25 11:53:09 +02:00
|
|
|
mkdir -p _afl_build_ubsan
|
|
|
|
cd _afl_build_ubsan
|
|
|
|
|
|
|
|
export AFL_USE_UBSAN=1
|
|
|
|
|
|
|
|
# build c-toxcore using afl instrumentation
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug "$COMMON_CMAKE_OPTIONS" ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target
|
|
|
|
cmake --build ./ --target bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
unset AFL_USE_UBSAN
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target MSAN
|
2023-07-25 11:53:09 +02:00
|
|
|
mkdir -p _afl_build_msan
|
|
|
|
cd _afl_build_msan
|
|
|
|
|
|
|
|
export AFL_USE_MSAN=1
|
|
|
|
|
|
|
|
# build c-toxcore using afl instrumentation
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug "$COMMON_CMAKE_OPTIONS" ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target
|
|
|
|
cmake --build ./ --target bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
unset AFL_USE_MSAN
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target ASAN
|
2023-07-25 11:53:09 +02:00
|
|
|
mkdir -p _afl_build_asan
|
|
|
|
cd _afl_build_asan
|
|
|
|
|
|
|
|
export AFL_USE_ASAN=1
|
|
|
|
|
|
|
|
# build c-toxcore using afl instrumentation
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug "$COMMON_CMAKE_OPTIONS" ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target
|
|
|
|
cmake --build ./ --target bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
unset AFL_USE_ASAN
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target without sanitizers for afl-tmin
|
2023-07-25 11:53:09 +02:00
|
|
|
mkdir -p _afl_build
|
|
|
|
cd _afl_build
|
|
|
|
|
|
|
|
# build c-toxcore using afl instrumentation
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug "$COMMON_CMAKE_OPTIONS" ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target
|
|
|
|
cmake --build ./ --target bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target with CmpLog
|
2023-07-25 11:53:09 +02:00
|
|
|
mkdir -p _afl_build_cmplog
|
|
|
|
cd _afl_build_cmplog
|
|
|
|
|
|
|
|
export AFL_LLVM_CMPLOG=1
|
|
|
|
|
|
|
|
# build c-toxcore using afl instrumentation
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug "$COMMON_CMAKE_OPTIONS" ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target
|
|
|
|
cmake --build ./ --target bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
unset AFL_LLVM_CMPLOG
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target for code coverage
|
2023-07-25 11:53:09 +02:00
|
|
|
mkdir -p _cov_build
|
|
|
|
cd _cov_build
|
|
|
|
|
|
|
|
# build c-toxcore using afl instrumentation
|
|
|
|
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage" -DCMAKE_C_FLAGS="-fprofile-arcs -ftest-coverage" -DCMAKE_VERBOSE_MAKEFILE=ON "$COMMON_CMAKE_OPTIONS" ..
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# build fuzz_test target
|
|
|
|
cmake --build ./ --target bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
# back to repo root
|
|
|
|
cd ../
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# Create fuzz_test working directory
|
2023-07-25 11:53:09 +02:00
|
|
|
|
|
|
|
mkdir -p _afl_out
|
|
|
|
|
|
|
|
AFL_ARGS='-i testing/afl_testdata/tox_bootstraps/ -o _afl_out'
|
|
|
|
|
|
|
|
export AFL_IMPORT_FIRST=1
|
|
|
|
export AFL_AUTORESUME=1
|
|
|
|
|
|
|
|
# faster startup
|
|
|
|
export AFL_FAST_CAL=1
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
echo "connect to the fuzz_tests using: screen -x fuzz"
|
2023-07-25 11:53:09 +02:00
|
|
|
echo "if fuzzing doesn't start execute the following as root:"
|
|
|
|
echo ""
|
|
|
|
echo "echo core >/proc/sys/kernel/core_pattern"
|
|
|
|
echo "echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor"
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# Main fuzz_test, keeps complete corpus
|
|
|
|
screen -dmS fuzz afl-fuzz -M fuzz0 "$AFL_ARGS" -c ./_afl_build_cmplog/bootstrap_fuzz_test ./_afl_build/bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
sleep 10s
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
# Secondary fuzz_tests
|
|
|
|
screen -S fuzz -X screen afl-fuzz -S fuzz1 "$AFL_ARGS" -- ./_afl_build_msan/bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
sleep 1s
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
screen -S fuzz -X screen afl-fuzz -S fuzz2 "$AFL_ARGS" ./_afl_build_ubsan/bootstrap_fuzz_test
|
2023-07-25 11:53:09 +02:00
|
|
|
sleep 1s
|
|
|
|
|
2024-01-14 21:51:01 +01:00
|
|
|
screen -S fuzz -X screen afl-fuzz -S fuzz3 "$AFL_ARGS" ./_afl_build_asan/bootstrap_fuzz_test
|