aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fuzz_default.sh
blob: 7418dff62b9beeb76db43ca96245517db04d41bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

set -eu

ZZSTARTSEED=0
ZZSTOPSEED=100
ret=0
# fallbacks for direct, non-"make check" usage
if test x"${testdatadir:-NONE}" = xNONE""
then
  testdatadir=../../test
fi
if test x"${bindir:-NONE}" = xNONE""
then
  bindir=`grep "^prefix = " ./Makefile | cut -d ' ' -f 3`
  bindir="$bindir/bin"
fi

if test ! -x `which zzuf`
then
    echo "zzuf not available, not running the test"
    exit 77
fi

if test -x `which timeout`
then
    TIMEOUT="timeout 15"
else
    echo "timeout command not found, will not auto-timeout (may cause hang)"
    TIMEOUT=""
fi

for file in $testdatadir/test*
do
  if test -f "$file"
  then
    tmpfile=`mktemp extractortmp.XXXXXX` || exit 1
    seed=$ZZSTARTSEED
    trap "echo $tmpfile caused SIGSEGV ; exit 1" SEGV
    while [ $seed -lt $ZZSTOPSEED ]
    do
      echo "file $file seed $seed"
      zzuf -c -s $seed cat "$file" > "$tmpfile"
      if ! $TIMEOUT $bindir/extract -i "$tmpfile" > /dev/null
      then
        echo "$tmpfile with seed $seed failed"
  	    mv $tmpfile $tmpfile.keep
	    ret=1
      fi
      seed=`expr $seed + 1`
    done
    rm -f "$tmpfile"
  fi
done

exit $ret