• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2019 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# Build libcbor, taken from oss-fuzz/projects/libcbor/build.sh
19# Note SANITIZE=OFF since it gets taken care of by $CFLAGS set by oss-fuzz
20cd ${SRC}/libcbor
21patch -l -p0 < ${SRC}/libfido2/fuzz/README
22mkdir build && cd build
23cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Debug \
24      -DCMAKE_INSTALL_PREFIX=${WORK} -DSANITIZE=OFF ..
25make -j$(nproc) VERBOSE=1
26make install
27
28# Build OpenSSL, taken from oss-fuzz/projects/openssl/build.sh
29cd ${SRC}/openssl
30CONFIGURE_FLAGS=""
31if [[ ${SANITIZER} = memory ]]
32then
33  CONFIGURE_FLAGS="no-asm"
34fi
35./config --debug no-tests ${CFLAGS} --prefix=${WORK} \
36	 --openssldir=${WORK}/openssl ${CONFIGURE_FLAGS}
37make -j$(nproc) LDCMD="${CXX} ${CXXFLAGS}"
38make install_sw
39
40# Build zlib, taken from oss-fuzz/projects/zlib.sh
41cd ${SRC}/zlib
42./configure --prefix=${WORK}
43make -j$(nproc) all
44make install
45
46# Building libfido2 with ${LIB_FUZZING_ENGINE} and chosen sanitizer
47cd ${SRC}/libfido2
48mkdir build && cd build
49cmake -DFUZZ=1 -DFUZZ_LDFLAGS=${LIB_FUZZING_ENGINE} \
50      -DPKG_CONFIG_USE_CMAKE_PREFIX_PATH=1 \
51      -DCMAKE_PREFIX_PATH=${WORK} \
52      -DCMAKE_INSTALL_PREFIX=${WORK} \
53      -DCMAKE_BUILD_TYPE=Debug ..
54make -j$(nproc)
55make install
56
57# Prepare ${OUT} with instrumented libs
58mkdir -p ${OUT}/lib
59for lib in `ls ${WORK}/lib/lib*.so*`; do
60    cp ${lib} ${OUT}/lib;
61done
62
63# Fixup rpath in the fuzzers so they use our libs
64for f in `ls fuzz/fuzz_*`; do
65    cp ${f} ${OUT}/
66    fuzzer=$(basename $f)
67    chrpath -r '$ORIGIN/lib' ${OUT}/${fuzzer}
68done
69
70 # Prepare seed corpora
71tar xzf ${SRC}/corpus.tgz
72(set -e ; cd fuzz_assert/corpus    ; zip -r ${OUT}/fuzz_assert_seed_corpus.zip .)
73(set -e ; cd fuzz_bio/corpus       ; zip -r ${OUT}/fuzz_bio_seed_corpus.zip .)
74(set -e ; cd fuzz_cred/corpus      ; zip -r ${OUT}/fuzz_cred_seed_corpus.zip .)
75(set -e ; cd fuzz_credman/corpus   ; zip -r ${OUT}/fuzz_credman_seed_corpus.zip .)
76(set -e ; cd fuzz_hid/corpus       ; zip -r ${OUT}/fuzz_hid_seed_corpus.zip .)
77(set -e ; cd fuzz_largeblob/corpus ; zip -r ${OUT}/fuzz_largeblob_seed_corpus.zip .)
78(set -e ; cd fuzz_mgmt/corpus      ; zip -r ${OUT}/fuzz_mgmt_seed_corpus.zip .)
79(set -e ; cd fuzz_netlink/corpus   ; zip -r ${OUT}/fuzz_netlink_seed_corpus.zip .)
80