Skip to content

Commit 887340c

Browse files
committed
Generalized fuzzing script
1 parent 7f7bcbf commit 887340c

File tree

3 files changed

+52
-33
lines changed

3 files changed

+52
-33
lines changed

tests/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in
22

33
dist_noinst_SCRIPTS = test-manpage.sh \
4+
test-fuzzing.sh \
45
test-pkcs11-tool-sign-verify.sh
56

67
TESTS = test-manpage.sh \

tests/test-fuzzing-pkcs15-tool-dump.sh

-33
This file was deleted.

tests/test-fuzzing.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
case "$1" in
6+
"pkcs11-tool")
7+
CMD="src/tools/pkcs11-tool --test --login --pin 123456"
8+
;;
9+
"pkcs15-tool")
10+
CMD="src/tools/pkcs15-tool --dump"
11+
;;
12+
"eidenv")
13+
CMD="src/tools/eidenv"
14+
;;
15+
*)
16+
echo "Unknown fuzzing target"
17+
exit 1
18+
;;
19+
esac
20+
21+
IN=tests/fuzzing-testcases
22+
if [ ! -d "$IN" ]
23+
then
24+
mkdir -p "$IN"
25+
echo -ne "$(printf '\\x90\\x00')" > "$IN"/9000
26+
fi
27+
28+
# reuse output directory if possible
29+
OUT="out-$1"
30+
if [ -d "$OUT" ]
31+
then
32+
IN=-
33+
fi
34+
35+
if [ ! -d x41-smartcard-fuzzing ];
36+
then
37+
git clone https://github.com/x41sec/x41-smartcard-fuzzing
38+
fi
39+
40+
gcc -shared -fPIC -o x41-smartcard-fuzzing/scard_override/libsccard_override.so x41-smartcard-fuzzing/scard_override/scard_override.c -ldl -I/usr/include/PCSC/
41+
42+
if [ ! -f configure ];
43+
then
44+
autoreconf -vis
45+
fi
46+
47+
#export AFL_USE_ASAN=1
48+
./configure CC=afl-gcc CFLAGS="-O0" --disable-shared --disable-notify --with-pcsc-provider=$PWD/x41-smartcard-fuzzing/scard_override/libsccard_override.so
49+
make
50+
51+
FUZZ_FILE=input.apdu afl-fuzz -i "$IN" -o "$OUT" -f input.apdu $CMD

0 commit comments

Comments
 (0)