7 read -r -a AVAILABLE_TARGETS < <(echo */fuzz.c | sed 's@/fuzz.c@@g')
12 Usage: $0 [OPTION]... [TARGET]...
14 Fuzz wimlib with afl-fuzz.
17 --asan Enable AddressSanitizer
18 --no-resume Don't resume existing afl-fuzz session; start a new one
19 --ubsan Enable UndefinedBehaviorSanitizer
21 Available targets: ${AVAILABLE_TARGETS[*]}
41 longopts=$(echo "${longopts_array[@]}" | tr ' ' ',')
43 if ! options=$(getopt -o "" -l "$longopts" -- "$@"); then
47 eval set -- "$options"
48 while (( $# >= 0 )); do
68 echo 1>&2 "Invalid option: \"$1\""
75 if $asan && $ubsan; then
76 die "--asan and --ubsan are mutually exclusive"
79 if ! type -P afl-fuzz > /dev/null; then
80 die "afl-fuzz is not installed"
83 if (( $# == 0 )); then
84 targets=("${AVAILABLE_TARGETS[@]}")
88 for t in "${AVAILABLE_TARGETS[@]}"; do
89 if [ "$target" = "$t" ]; then
94 echo 1>&2 "Unknown target '$target'"
95 echo 1>&2 "Available targets: ${AVAILABLE_TARGETS[*]}"
101 if (( ${#targets[@]} > 1 )) && ! type -P urxvt > /dev/null; then
102 die "urxvt is not installed"
107 export AFL_USE_ASAN=1
108 export CFLAGS="-O2 -m32"
112 export CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined"
120 sudo sh -c "echo core > /proc/sys/kernel/core_pattern"
121 sudo sh -c "echo performance | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor"
123 NPROC=$(getconf _NPROCESSORS_ONLN)
127 ./configure CC="$CC" CFLAGS="$CFLAGS"
131 export LD_LIBRARY_PATH=$PWD/../../.libs
133 for dir in "${targets[@]}"; do
134 workdir=/tmp/wimlib_$dir
135 cp -vaT "$dir" "$workdir"
136 indir=$workdir/inputs
137 outdir=$workdir/outputs
138 if [ -e "$outdir" ]; then
142 rm -rf "${outdir:?}"/*
147 cmd="afl-fuzz -i $indir -o $outdir -T wimlib_$dir $afl_opts -- $workdir/fuzz @@"
148 if (( ${#targets[@]} > 1 )); then
149 urxvt -e bash -c "$cmd" &