From 2d0b3ec6a2f021b233f776d623fdfad8e07fb44c Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Mon, 15 Apr 2024 15:34:51 +0200 Subject: [PATCH] Some extra scripting for dealing with fuzzers * check.sh: uses the oss-fuzz infrastructure scripts to run over various fuzzing engines, trying to build the fuzzers and run a sanity check on them * local.sh: builds the fuzzers locally with some minor assumptions on locations Signed-off-by: Erik Boasson --- fuzz/check.sh | 26 ++++++++++++++++++ fuzz/local.sh | 48 ++++++++++++++++++++++++++++++++++ src/core/xtests/CMakeLists.txt | 2 +- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100755 fuzz/check.sh create mode 100644 fuzz/local.sh diff --git a/fuzz/check.sh b/fuzz/check.sh new file mode 100755 index 0000000000..3e7463aeb3 --- /dev/null +++ b/fuzz/check.sh @@ -0,0 +1,26 @@ +#!/usr/bin/bash + +if [ ! -f "infra/helper.py" ] ; then + echo "this script must be executed in the oss-fuzz directory" 2>&1 + exit 33 +fi + +if [ "$1" = "build-image" ] ; then + shift + python3 infra/helper.py build_image cyclonedds +fi + +if [ ! -d "$1" -o ! -f "$1/src/core/ddsi/src/ddsi_init.c" ] ; then + echo "usage: $0 [build-image] cyclone-source-dir" 2>&1 + exit 33 +fi +srcdir="$1" + +set -x +engines="libfuzzer afl honggfuzz centipede" +for eng in $engines ; do + echo "********** ENGINE = $eng **********" + sudo rm -rf $srcdir/{build,install,build_python} + python3 infra/helper.py build_fuzzers --sanitizer address --engine $eng cyclonedds $srcdir || break + python3 infra/helper.py check_build --engine $eng cyclonedds || break +done diff --git a/fuzz/local.sh b/fuzz/local.sh new file mode 100644 index 0000000000..fcde516a59 --- /dev/null +++ b/fuzz/local.sh @@ -0,0 +1,48 @@ +#!/usr/bin/bash + +# Local build +# +# sudo apt install clang libfuzzer-14-dev (replace 14 with clang version) + +set -ex + +if [ ! -f ../src/core/ddsi/src/ddsi_receive.c -o ! -d ../fuzz ] ; then + echo "This expects to be run in a build directory that is a subdirectory of the Cyclone repo" 2>&1 + exit 1 +fi +if [ -z "$CYCLONEDDS_HOME" ] ; then + echo "Need CYCLONEDDS_HOME to be set" 2>&1 +fi +if [ -z "$CYCLONEDDS_PYTHON" -o ! -d "$CYCLONEDDS_PYTHON/tests/support_modules/fuzz_tools" ] ; then + echo "need CYCLONEDDS_PYTHON to point to the cyclone python binding sources" 2>&1 + exit 1 +fi + +export PATH="$CYCLONEDDS_HOME/bin:$PATH" +export LD_LIBRARY_PATH="$CYCLONEDDS_HOME/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" +export PATH="$CYCLONEDDS_HOME/lib:$PATH" +export PYTHONPATH="$CYCLONEDDS_PYTHON/tests/support_modules${PYTHONPATH:+:$PYTHONPATH}" + +# Use current git HEAD hash as seed +[ -z "$SEED" ] && SEED=$(git ls-remote https://github.com/eclipse-cyclonedds/cyclonedds HEAD |cut -f1) +python3 "../fuzz/fuzz_sample_deser/generate_idl.py" $SEED "../fuzz/fuzz_sample_deser" + +export CC=clang +export CXX=clang++ +export LIB_FUZZING_ENGINE=/usr/lib/llvm-14/lib/libFuzzer.a + +cmake -G Ninja \ + -DSANITIZER=address,undefined,fuzzer \ + -DEXPORT_ALL_SYMBOLS=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_EXAMPLES=NO \ + -DENABLE_SECURITY=ON \ + -DENABLE_SSL=NO \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_IDLC=NO \ + -DBUILD_DDSPERF=NO \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_PREFIX_PATH=$PWD/host_install \ + -DCMAKE_INSTALL_PREFIX=$PWD/install .. + +cmake --build . diff --git a/src/core/xtests/CMakeLists.txt b/src/core/xtests/CMakeLists.txt index 406a625782..e913404409 100644 --- a/src/core/xtests/CMakeLists.txt +++ b/src/core/xtests/CMakeLists.txt @@ -15,6 +15,6 @@ if(BUILD_TESTING AND BUILD_IDLC) add_subdirectory(initsampledeliv) endif() -if(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_SYSTEM_NAME MATCHES "iOS") +if(NOT CMAKE_CROSSCOMPILING AND NOT CMAKE_SYSTEM_NAME MATCHES "iOS" AND NOT DEFINED ENV{LIB_FUZZING_ENGINE}) add_subdirectory(symbol_export) endif()