|
| 1 | +#!/bin/bash -eu |
| 2 | + |
| 3 | +pip3 install . |
| 4 | + |
| 5 | +# Build fuzzers into $OUT. These could be detected in other ways. |
| 6 | +for fuzzer in $(find $SRC -name 'fuzzer_*.py'); do |
| 7 | + fuzzer_basename=$(basename -s .py $fuzzer) |
| 8 | + fuzzer_package=${fuzzer_basename}.pkg |
| 9 | + |
| 10 | + # To avoid issues with Python version conflicts, or changes in environment |
| 11 | + # over time, we use pyinstaller to create a standalone |
| 12 | + # package. Though not necessarily required for reproducing issues, this is |
| 13 | + # required to keep fuzzers working properly. |
| 14 | + pyinstaller --distpath $OUT --onefile --name $fuzzer_package $fuzzer |
| 15 | + |
| 16 | + # Create execution wrapper. Atheris requires that certain libraries are |
| 17 | + # preloaded, so this is also done here to ensure compatibility and simplify |
| 18 | + # test case reproduction. Since this helper script is what will |
| 19 | + # actually execute, it is also always required. |
| 20 | + # NOTE: If you are fuzzing python-only code and do not have native C/C++ |
| 21 | + # extensions, then remove the LD_PRELOAD line below as preloading sanitizer |
| 22 | + # library is not required and can lead to unexpected startup crashes. |
| 23 | + echo "#!/bin/sh |
| 24 | +# LLVMFuzzerTestOneInput for fuzzer detection. |
| 25 | +this_dir=\$(dirname \"\$0\") |
| 26 | +LD_PRELOAD=\$this_dir/sanitizer_with_fuzzer.so \ |
| 27 | +ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \ |
| 28 | +\$this_dir/$fuzzer_package \$@" > $OUT/$fuzzer_basename |
| 29 | + chmod +x $OUT/$fuzzer_basename |
| 30 | +done |
0 commit comments