Skip to content

Commit

Permalink
Some extra scripting for dealing with fuzzers
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
eboasson committed Apr 16, 2024
1 parent 64066d8 commit 2d0b3ec
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
26 changes: 26 additions & 0 deletions fuzz/check.sh
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions fuzz/local.sh
Original file line number Diff line number Diff line change
@@ -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 .
2 changes: 1 addition & 1 deletion src/core/xtests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 2d0b3ec

Please sign in to comment.