|
| 1 | +#!/bin/bash -eu |
| 2 | +# Copyright 2016 Google Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +# |
| 16 | +################################################################################ |
| 17 | + |
| 18 | +export FUZZ_INTROSPECTOR_CONFIG=$SRC/openssl/fuzz/fuzz_introspector_exclusion.config |
| 19 | + |
| 20 | +CONFIGURE_FLAGS="--debug enable-fuzz-libfuzzer -DPEDANTIC -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION no-shared enable-tls1_3 enable-rc5 enable-md2 enable-ssl3 enable-ssl3-method enable-nextprotoneg enable-weak-ssl-ciphers --with-fuzzer-lib=/usr/lib/libFuzzingEngine $CFLAGS -fno-sanitize=alignment" |
| 21 | +if [[ $CFLAGS = *sanitize=memory* ]] |
| 22 | +then |
| 23 | + CONFIGURE_FLAGS="$CONFIGURE_FLAGS no-asm" |
| 24 | +fi |
| 25 | +if [[ $CFLAGS != *-m32* ]] |
| 26 | +then |
| 27 | + CONFIGURE_FLAGS="$CONFIGURE_FLAGS enable-ec_nistp_64_gcc_128" |
| 28 | +fi |
| 29 | +if [[ $CFLAGS = *-m32* ]] |
| 30 | +then |
| 31 | + # Prevent error: |
| 32 | + # |
| 33 | + # error while loading shared libraries: |
| 34 | + # libatomic.so.1: cannot open shared object file: |
| 35 | + # No such file or directory |
| 36 | + CONFIGURE_FLAGS="$CONFIGURE_FLAGS no-threads" |
| 37 | +fi |
| 38 | + |
| 39 | +function build_fuzzers() { |
| 40 | + SUFFIX=$1 |
| 41 | + if [[ $CFLAGS = *-m32* ]] |
| 42 | + then |
| 43 | + setarch i386 ./config $CONFIGURE_FLAGS |
| 44 | + else |
| 45 | + ./config $CONFIGURE_FLAGS |
| 46 | + fi |
| 47 | + |
| 48 | + make -j$(nproc) LDCMD="$CXX $CXXFLAGS" |
| 49 | + |
| 50 | + fuzzers=$(find fuzz -executable -type f '!' -name \*.py '!' -name \*-test '!' -name \*.pl '!' -name \*.sh) |
| 51 | + for f in $fuzzers; do |
| 52 | + fuzzer=$(basename $f) |
| 53 | + cp $f $OUT/${fuzzer}${SUFFIX} |
| 54 | + zip -j $OUT/${fuzzer}${SUFFIX}_seed_corpus.zip fuzz/corpora/${fuzzer}/* |
| 55 | + done |
| 56 | + |
| 57 | + options=$(find $SRC/ -maxdepth 1 -name '*.options') |
| 58 | + for o in $options; do |
| 59 | + o_base=$(basename $o) |
| 60 | + fuzzer=${o_base%".options"} |
| 61 | + cp $o $OUT/${fuzzer}${SUFFIX}.options |
| 62 | + done |
| 63 | + cp fuzz/oids.txt $OUT/asn1${SUFFIX}.dict |
| 64 | + cp fuzz/oids.txt $OUT/x509${SUFFIX}.dict |
| 65 | + if [ "$SANITIZER" == coverage ]; then |
| 66 | + DESTDIR=$OUT/src/openssl${SUFFIX#_} |
| 67 | + SOURCES="include crypto ssl providers engines fuzz" |
| 68 | + mkdir -p $DESTDIR |
| 69 | + if [ -f e_os.h ]; then |
| 70 | + cp e_os.h $DESTDIR/ |
| 71 | + fi |
| 72 | + find $SOURCES -type f -a \( -name '*.[ch]' -o -name '*.inc' \) -exec cp --parents '{}' $DESTDIR/ \; |
| 73 | + fi |
| 74 | + df |
| 75 | + rm -rf * .git* |
| 76 | + df |
| 77 | +} |
| 78 | + |
| 79 | +cd $SRC/openssl/ |
| 80 | +build_fuzzers "" |
| 81 | + |
| 82 | +# In introspector only build the master branch |
| 83 | +if [[ "$SANITIZER" == introspector ]]; then |
| 84 | + exit 0 |
| 85 | +fi |
| 86 | + |
| 87 | +cd $SRC/openssl30/ |
| 88 | +build_fuzzers "_30" |
| 89 | +cd $SRC/openssl31/ |
| 90 | +build_fuzzers "_31" |
| 91 | +cd $SRC/openssl32/ |
| 92 | +build_fuzzers "_32" |
0 commit comments