1#!/bin/bash -u 2# Copyright 2020 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17cd $OUT 18 19if (( $# > 0 )); then 20 FUZZ_TARGETS="$@" 21else 22 FUZZ_TARGETS="$(find . -maxdepth 1 -type f -executable -printf '%P\n')" 23fi 24 25# Timeout for running a single fuzz target. 26TIMEOUT=1h 27 28# Number of CPUs available, this is needed for running targets in parallel. 29NPROC=$(nproc) 30 31function run_one_target { 32 local target=$1 33 local corpus="/corpus/${target}" 34 local traces="$OUT/${target}_dft" 35 36 # Put the logs in $OUT as well for debugging purposes. 37 local log="$OUT/${target}_dft.log" 38 39 rm -rf $traces && mkdir -p $traces 40 41 timeout $TIMEOUT dataflow_tracer.py $OUT/$target $corpus $traces &> $log 42 if (( $? != 0 )); then 43 echo "Error occured while collecting data flow traces for $target:" 44 cat $log 45 fi 46} 47 48# Run each fuzz target, write data flow traces into corresponding dir in $OUT. 49for fuzz_target in $FUZZ_TARGETS; do 50 # Skip binaries that do not seem to be fuzz targets. 51 grep "LLVMFuzzerTestOneInput" $fuzz_target > /dev/null 2>&1 || continue 52 53 echo "Running $fuzz_target" 54 run_one_target $fuzz_target & 55 56 # Do not spawn more processes than the number of CPUs available. 57 n_child_proc=$(jobs -rp | wc -l) 58 while [ "$n_child_proc" -eq "$NPROC" ]; do 59 sleep 4 60 n_child_proc=$(jobs -rp | wc -l) 61 done 62done 63 64# Wait for background processes to finish. 65wait 66