ossfuzz.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash -eu
  2. # Go to tests folder
  3. cd "$( dirname "${BASH_SOURCE[0]}" )/.."
  4. # Build seed corpus.
  5. # Generating it here ensures it will contain all of the fields in the AllTypes
  6. # test case. The generators are built without fuzzing instrumentation.
  7. rm -rf build
  8. scons build/alltypes/encode_alltypes build/fuzztest/generate_message
  9. mkdir fuzztest_seed_corpus
  10. build/alltypes/encode_alltypes 0 > fuzztest_seed_corpus/alltypes0
  11. build/alltypes/encode_alltypes 1 > fuzztest_seed_corpus/alltypes1
  12. build/alltypes/encode_alltypes 2 > fuzztest_seed_corpus/alltypes2
  13. build/fuzztest/generate_message $(date +%s) > fuzztest_seed_corpus/rndmsg 2>/dev/null
  14. for f in fuzztest_seed_corpus/*; do
  15. mv $f fuzztest_seed_corpus/$(sha1sum $f | cut -f 1 -d ' ')
  16. done
  17. zip -r "$OUT/corpus.zip" fuzztest_seed_corpus
  18. # Build the fuzz testing stubs with instrumentation
  19. rm -rf build
  20. FUZZERS="build/fuzztest/fuzztest_proto2_static
  21. build/fuzztest/fuzztest_proto2_pointer
  22. build/fuzztest/fuzztest_proto3_static
  23. build/fuzztest/fuzztest_proto3_pointer
  24. build/fuzztest/fuzztest_io_errors"
  25. scons CC="$CC" CXX="$CXX" LINK="$CXX" \
  26. CCFLAGS="-Wall -Wextra -g -DLLVMFUZZER $CFLAGS" \
  27. CXXFLAGS="-Wall -Wextra -g -DLLVMFUZZER $CXXFLAGS" \
  28. NODEFARGS="1" \
  29. LINKFLAGS="-std=c++11 $CXXFLAGS" \
  30. LINKLIBS="$LIB_FUZZING_ENGINE" $FUZZERS
  31. cp $FUZZERS "$OUT"
  32. # The fuzzer test cases are closely related, so use the same seed corpus
  33. # for all of them.
  34. for fuzzer in $FUZZERS
  35. do cp "$OUT/corpus.zip" "$OUT/$(basename $fuzzer)_seed_corpus.zip"
  36. done
  37. rm "$OUT/corpus.zip"