Home | History | Annotate | Download | only in openssl
      1 #!/bin/sh
      2 
      3 set -x
      4 set -e
      5 
      6 DIR="$1"
      7 SAN="$2"
      8 TYPE=`basename "$DIR"`
      9 HFUZZ_SRC=~/src/honggfuzz/
     10 OS=`uname -s`
     11 CLANG_VER=-5.0
     12 CC="$HFUZZ_SRC/hfuzz_cc/hfuzz-clang"
     13 CXX="$HFUZZ_SRC/hfuzz_cc/hfuzz-clang++"
     14 COMMON_FLAGS="-DBORINGSSL_UNSAFE_DETERMINISTIC_MODE -DBORINGSSL_UNSAFE_FUZZER_MODE -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -DBN_DEBUG \
     15 	-O3 -g -DFuzzerInitialize=LLVMFuzzerInitialize -DFuzzerTestOneInput=LLVMFuzzerTestOneInput \
     16 	-I./$DIR/include -I$HFUZZ_SRC/examples/openssl -I$HFUZZ_SRC"
     17 COMMON_LDFLAGS="-lpthread -lz -Wl,-z,now"
     18 
     19 if [ -z "$DIR" ]; then
     20 	echo "$0" DIR SANITIZE
     21 	exit 1
     22 fi
     23 
     24 LIBSSL="`find "$DIR" -type f -name 'libssl.a' | head -n1`"
     25 if [ -z "$LIBSSL" ]; then
     26 	echo "Couldn't find libssl.a inside $DIR"
     27 	exit 1
     28 fi
     29 
     30 LIBCRYPTO="`find "$DIR" -type f -name 'libcrypto.a' | head -n1`"
     31 if [ -z "$LIBCRYPTO" ]; then
     32 	echo "Couldn't find libcrypto.a inside $DIR"
     33 	exit 1
     34 fi
     35 
     36 
     37 if [ "$OS" = "Linux" ]; then
     38 	COMMON_LDFLAGS="$COMMON_LDFLAGS -ldl"
     39 fi
     40 
     41 if [ -n "$SAN" ]; then
     42 	SAN_COMPILE="-fsanitize=$SAN"
     43 	SAN=".$SAN"
     44 fi
     45 
     46 for x in x509 privkey client server; do
     47 	$CC $COMMON_FLAGS -g "$HFUZZ_SRC/examples/openssl/$x.c" -o "$TYPE$SAN.$x$SUFFIX" "$LIBSSL" "$LIBCRYPTO" $COMMON_LDFLAGS $SAN_COMPILE
     48 done
     49 
     50 for x in x509 privkey client server; do
     51 	$CC $COMMON_FLAGS -DHF_SSL_FROM_STDIN -g "$HFUZZ_SRC/examples/openssl/$x.c" -o "stdin.$TYPE$SAN.$x" "$LIBSSL" "$LIBCRYPTO" $COMMON_LDFLAGS $SAN_COMPILE
     52 done
     53 
     54 for x in x509 privkey client server; do
     55 	clang++$CLANG_VER $COMMON_FLAGS -g "$HFUZZ_SRC/examples/openssl/$x.c" -o "libfuzzer.$TYPE$SAN.$x$SUFFIX" "$LIBSSL" "$LIBCRYPTO" $COMMON_LDFLAGS $SAN_COMPILE -lFuzzer
     56 done
     57 
     58