• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh -eu
2#
3# Copyright(c) 2017-2018 Tim Ruehsen
4#
5# Permission is hereby granted, free of charge, to any person obtaining a
6# copy of this software and associated documentation files (the "Software"),
7# to deal in the Software without restriction, including without limitation
8# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9# and/or sell copies of the Software, and to permit persons to whom the
10# Software is furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21# DEALINGS IN THE SOFTWARE.
22#
23# This file is part of libpsl.
24
25srcdir="${srcdir:-.}"
26export LD_LIBRARY_PATH=${srcdir}/../lib/.libs/
27
28cat ${srcdir}/../config.log|grep afl-clang-fast >/dev/null 2>&1
29if test $? != 0; then
30	echo "compile first library as:"
31	echo "CC=afl-clang-fast ./configure"
32	exit 1
33fi
34
35if test -z "$1"; then
36	echo "Usage: $0 test-case"
37	echo "Example: $0 libpsl_fuzzer"
38	exit 1
39fi
40
41rm -f $1
42CFLAGS="-g -O2" CC=afl-clang-fast make "$1" || exit 1
43
44### minimize test corpora
45if test -d ${fuzzer}.in; then
46  mkdir -p ${fuzzer}.min
47  for i in `ls ${fuzzer}.in`; do
48    fin="${fuzzer}.in/$i"
49    fmin="${fuzzer}.min/$i"
50    if ! test -e $fmin || test $fin -nt $fmin; then
51      afl-tmin -i $fin -o $fmin -- ./${fuzzer}
52    fi
53  done
54fi
55
56TMPOUT=${fuzzer}.$$.out
57mkdir -p ${TMPOUT}
58
59if test -f ${fuzzer}.dict; then
60  afl-fuzz -i ${fuzzer}.min -o ${TMPOUT} -x ${fuzzer}.dict -- ./${fuzzer}
61else
62  afl-fuzz -i ${fuzzer}.min -o ${TMPOUT} -- ./${fuzzer}
63fi
64
65echo "output was stored in $TMPOUT"
66
67exit 0
68