github.com/google/syzkaller@v0.0.0-20251211124644-a066d2bc4b02/tools/syz-reproducers.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2024 syzkaller project authors. All rights reserved. 3 # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 4 5 # This tool uses syz-db-export artifacts. 6 # See https://github.com/google/syzkaller/tree/master/tools/syz-db-export documentation. 7 8 # Check if the target directory is provided as a command line argument. 9 if [ -z "$1" ]; then 10 echo "Usage: $0 <target_directory>" 11 exit 1 12 fi 13 14 target_dir="$1" 15 16 # Create the target directory if it doesn't exist. 17 mkdir -p "$target_dir" 18 19 # Download the archive to the target directory. 20 wget -P "$target_dir" https://storage.googleapis.com/artifacts.syzkaller.appspot.com/shared-files/repro-export/upstream.tar.gz 21 22 # Extract the archive in the target directory and then delete it. 23 tar -xzf "$target_dir/upstream.tar.gz" -C "$target_dir" && rm "$target_dir/upstream.tar.gz" 24 25 # Create the bin directory inside the target directory. 26 mkdir -p "$target_dir/bin" 27 28 # Compile the programs and count the successfully built ones. 29 built_count=$(find "$target_dir/export/bugs" -name "*.c" -print0 | \ 30 xargs -0 -P 128 -I {} sh -c ' 31 filename=$(basename {} .c) 32 flags="" 33 if grep "__NR_mmap2" {}; then 34 flags="-m32" 35 fi 36 if gcc {} $flags -static -pthread -o "'"$target_dir"'/bin/$filename" ; then 37 echo 1 # Output 1 if compilation is successful 38 else 39 echo 0 # Output 0 if compilation fails 40 fi 41 ' | grep "1" | wc -l) 42 43 # Count the number of .c files (reproducers). 44 reproducer_count=$(find "$target_dir/export/bugs" -name "*.c" -print0 | xargs -0 -n1 echo | wc -l) 45 46 echo "Downloaded $reproducer_count reproducers." 47 echo "Successfully built $built_count programs."