Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2020-11-13 15:21:41 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2020-11-13 15:21:41 +0300
commit289350adb677651cade9290b1ce4af58fa1a4b07 (patch)
treec93a74bc9c9209f2d689d1126dbca35329b598fe
parent7db1210f9796250cc46c01fe27b27b4a7dafc275 (diff)
Add OSSFuzz build script to main repo.
-rw-r--r--tests/fuzztest/ossfuzz.sh45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/fuzztest/ossfuzz.sh b/tests/fuzztest/ossfuzz.sh
new file mode 100644
index 0000000..f662e06
--- /dev/null
+++ b/tests/fuzztest/ossfuzz.sh
@@ -0,0 +1,45 @@
+#!/bin/bash -eu
+
+# Go to tests folder
+cd "$( dirname "${BASH_SOURCE[0]}" )/.."
+
+# Build seed corpus.
+# Generating it here ensures it will contain all of the fields in the AllTypes
+# test case. The generators are built without fuzzing instrumentation.
+rm -rf build
+scons build/alltypes/encode_alltypes build/fuzztest/generate_message
+mkdir fuzztest_seed_corpus
+build/alltypes/encode_alltypes 0 > fuzztest_seed_corpus/alltypes0
+build/alltypes/encode_alltypes 1 > fuzztest_seed_corpus/alltypes1
+build/alltypes/encode_alltypes 2 > fuzztest_seed_corpus/alltypes2
+build/fuzztest/generate_message $(date +%s) > fuzztest_seed_corpus/rndmsg 2>/dev/null
+for f in fuzztest_seed_corpus/*; do
+ mv $f fuzztest_seed_corpus/$(sha1sum $f | cut -f 1 -d ' ')
+done
+zip -r "$OUT/corpus.zip" fuzztest_seed_corpus
+
+# Build the fuzz testing stubs with instrumentation
+rm -rf build
+
+FUZZERS="build/fuzztest/fuzztest_proto2_static
+ build/fuzztest/fuzztest_proto2_pointer
+ build/fuzztest/fuzztest_proto3_static
+ build/fuzztest/fuzztest_proto3_pointer
+ build/fuzztest/fuzztest_io_errors"
+
+scons CC="$CC" CXX="$CXX" LINK="$CXX" \
+ CCFLAGS="-Wall -Wextra -g -DLLVMFUZZER $CFLAGS" \
+ CXXFLAGS="-Wall -Wextra -g -DLLVMFUZZER $CXXFLAGS" \
+ NODEFARGS="1" \
+ LINKFLAGS="-std=c++11 $CXXFLAGS" \
+ LINKLIBS="$LIB_FUZZING_ENGINE" $FUZZERS
+
+cp $FUZZERS "$OUT"
+
+# The fuzzer test cases are closely related, so use the same seed corpus
+# for all of them.
+for fuzzer in $FUZZERS
+ do cp "$OUT/corpus.zip" "$OUT/$(basename $fuzzer)_seed_corpus.zip"
+done
+rm "$OUT/corpus.zip"
+