1#!/bin/bash -eux 2# 3# Copyright 2016 Google Inc. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17################################################################################ 18mkdir -p $WORK/boringssl 19cd $WORK/boringssl 20 21CFLAGS="$CFLAGS -DBORINGSSL_UNSAFE_FUZZER_MODE" 22CXXFLAGS="$CXXFLAGS -DBORINGSSL_UNSAFE_FUZZER_MODE" 23 24CMAKE_DEFINES="-DBORINGSSL_ALLOW_CXX_RUNTIME=1" 25if [[ $CFLAGS = *sanitize=memory* ]] 26then 27 CMAKE_DEFINES+=" -DOPENSSL_NO_ASM=1" 28fi 29 30cmake -GNinja -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \ 31 -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \ 32 $CMAKE_DEFINES $SRC/boringssl/ 33ninja 34 35fuzzerFiles=$(find $SRC/boringssl/fuzz/ -name "*.cc") 36 37find . -name "*.a" 38 39for F in $fuzzerFiles; do 40 fuzzerName=$(basename $F .cc) 41 echo "Building fuzzer $fuzzerName" 42 $CXX $CXXFLAGS -std=c++11 \ 43 -o $OUT/${fuzzerName} $LIB_FUZZING_ENGINE $F \ 44 -I $SRC/boringssl/include ./ssl/libssl.a ./crypto/libcrypto.a 45 46 if [ -d "$SRC/boringssl/fuzz/${fuzzerName}_corpus" ]; then 47 zip -j $OUT/${fuzzerName}_seed_corpus.zip $SRC/boringssl/fuzz/${fuzzerName}_corpus/* 48 fi 49done 50 51if [[ $CFLAGS != *sanitize=memory* ]]; then 52 fuzzerLPMFiles=$(find $SRC/ -maxdepth 1 -name "*.cc") 53 54 cp $SRC/fuzzing/proto/asn1-pdu/* $SRC/ 55 56 rm -rf genfiles && mkdir genfiles && $SRC/LPM/external.protobuf/bin/protoc asn1_pdu.proto --cpp_out=genfiles --proto_path=$SRC/ 57 58 for F in $fuzzerLPMFiles 59 do 60 fuzzerName=$(echo ${F#*_}) 61 fuzzerName=$(basename $fuzzerName .cc) 62 echo "Building fuzzer $fuzzerName" 63 $CXX $CXXFLAGS -I genfiles -I . -I $SRC/libprotobuf-mutator/ -I $SRC/LPM/external.protobuf/include -I include $LIB_FUZZING_ENGINE \ 64 -I $SRC/boringssl/include \ 65 $F genfiles/asn1_pdu.pb.cc $SRC/asn1_pdu_to_der.cc $SRC/common.cc \ 66 ./ssl/libssl.a ./crypto/libcrypto.a \ 67 $SRC/LPM/src/libfuzzer/libprotobuf-mutator-libfuzzer.a \ 68 $SRC/LPM/src/libprotobuf-mutator.a \ 69 $SRC/LPM/external.protobuf/lib/libprotobuf.a \ 70 -o $OUT/"${fuzzerName}_lpm" 71 done 72fi 73