summaryrefslogtreecommitdiff
path: root/build/fuzz/run-afl.sh
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@redhat.com>2017-05-22 15:31:23 +0200
committerDaiki Ueno <ueno@gnu.org>2017-05-22 15:57:52 +0200
commit8b64577c3bb4d5dd60e4939223550f2f2002284b (patch)
treed5a63bb8665388d8135d49aa5f29f15304b42cc0 /build/fuzz/run-afl.sh
parent723dfeb3dd9b8426c4c1d6236f4b22354c122dae (diff)
build: Add fuzzer using AFL
Diffstat (limited to 'build/fuzz/run-afl.sh')
-rwxr-xr-xbuild/fuzz/run-afl.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/build/fuzz/run-afl.sh b/build/fuzz/run-afl.sh
new file mode 100755
index 0000000..95c6c43
--- /dev/null
+++ b/build/fuzz/run-afl.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# Copyright (C) 2017 Red Hat, Inc.
+#
+# This file is part of GnuTLS.
+#
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+srcdir="${srcdir:-.}"
+export LD_LIBRARY_PATH=${srcdir}/../../lib/.libs/
+
+cat ${srcdir}/../../config.log|grep afl-gcc >/dev/null 2>&1
+if test $? != 0;then
+ echo "compile first library as:"
+ echo "CC=afl-gcc ./configure"
+ exit 1
+fi
+
+if test -z "$1";then
+ echo "Usage: $0 test-case"
+ echo "Example: $0 gnutls_x509_parser_fuzzer"
+ exit 1
+fi
+
+rm -f $1
+CFLAGS="-g -O2" CC=afl-gcc make $1 || exit 1
+
+TEST=$(echo $1|sed s/_fuzzer//)
+
+TMPOUT=${TEST}.$$.out
+mkdir -p ${TMPOUT}
+afl-fuzz -i ${TEST}.in -o ${TMPOUT} -- ./${TEST}_fuzzer
+
+echo "output was stored in $TMPOUT"
+
+exit 0