aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fuzz_default.sh
blob: 67292cf68afb02448696b3219dcd914c5662f72b (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
#!/bin/sh

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

if test -x `which zzuf`
then
    exit 77
fi

if test -x `which timeout`
then
    TIMEOUT=timeout 15
else
    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