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