2
0

build.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # shellcheck shell=bash
  2. set -euo pipefail
  3. python3 -m pip install .
  4. # Directory to look in for dictionaries, options files, and seed corpora:
  5. SEED_DATA_DIR="$SRC/seed_data"
  6. find "$SEED_DATA_DIR" \( -name '*_seed_corpus.zip' -o -name '*.options' -o -name '*.dict' \) \
  7. ! \( -name '__base.*' \) -exec printf 'Copying: %s\n' {} \; \
  8. -exec chmod a-x {} \; \
  9. -exec cp {} "$OUT" \;
  10. # Build fuzzers in $OUT.
  11. find "$SRC/dulwich/fuzzing" -name 'fuzz_*.py' -print0 | while IFS= read -r -d '' fuzz_harness; do
  12. compile_python_fuzzer "$fuzz_harness"
  13. common_base_dictionary_filename="$SEED_DATA_DIR/__base.dict"
  14. if [[ -r "$common_base_dictionary_filename" ]]; then
  15. # Strip the `.py` extension from the filename and replace it with `.dict`.
  16. fuzz_harness_dictionary_filename="$(basename "$fuzz_harness" .py).dict"
  17. output_file="$OUT/$fuzz_harness_dictionary_filename"
  18. printf 'Appending %s to %s\n' "$common_base_dictionary_filename" "$output_file"
  19. if [[ -s "$output_file" ]]; then
  20. # If a dictionary file for this fuzzer already exists and is not empty,
  21. # we append a new line to the end of it before appending any new entries.
  22. #
  23. # LibFuzzer will happily ignore multiple empty lines in a dictionary but fail with an error
  24. # if any single line has incorrect syntax (e.g., if we accidentally add two entries to the same line.)
  25. # See docs for valid syntax: https://llvm.org/docs/LibFuzzer.html#id32
  26. echo >>"$output_file"
  27. fi
  28. cat "$common_base_dictionary_filename" >>"$output_file"
  29. fi
  30. done