• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2020 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
18cd $SRC
19
20wget -qO- https://botan.randombit.net/releases/Botan-2.16.0.tar.xz | tar xJ
21cd Botan-2.16.0
22./configure.py --prefix=/usr --cc-bin=$CXX --cc-abi-flags="$CXXFLAGS" \
23               --disable-modules=locking_allocator \
24               --unsafe-fuzzer-mode --build-fuzzers=libfuzzer \
25               --with-fuzzer-lib='FuzzingEngine'
26make -j$(nproc)
27make install
28
29cd $SRC
30mkdir fuzzing_corpus
31
32cd $SRC/rnp/src/tests/data
33find . -type f -print0 | xargs -0 -I bob -- cp bob $SRC/fuzzing_corpus/
34
35# -DENABLE_SANITIZERS=0 because oss-fuzz will add the sanitizer flags in CFLAGS
36# See https://github.com/google/oss-fuzz/pull/4189 to explain CMAKE_C_LINK_EXECUTABLE
37
38cd $SRC
39mkdir rnp-build
40cd rnp-build
41cmake \
42    -DENABLE_SANITIZERS=0 \
43    -DENABLE_FUZZERS=1 \
44    -DCMAKE_C_COMPILER=$CC \
45    -DCMAKE_CXX_COMPILER=$CXX \
46    -DCMAKE_C_LINK_EXECUTABLE="$CXX <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>" \
47    -DCMAKE_INSTALL_PREFIX=/usr \
48    -DBUILD_SHARED_LIBS=on \
49    -DBUILD_TESTING=off \
50    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
51    $SRC/rnp
52make -j$(nproc)
53
54FUZZERS=`find src/fuzzing -maxdepth 1 -type f -name "fuzz_*" -exec basename {} \;`
55printf "Detected fuzzers: \n$FUZZERS\n"
56for f in $FUZZERS; do
57    cp src/fuzzing/$f "${OUT}/"
58    patchelf --set-rpath '$ORIGIN/lib' "${OUT}/$f" || echo "patchelf failed with $?, ignoring."
59    zip -j -r "${OUT}/${f}_seed_corpus.zip" $SRC/fuzzing_corpus/
60done
61
62mkdir -p "${OUT}/lib"
63cp src/lib/librnp.so.0 "${OUT}/lib/"
64cp /usr/lib/libbotan-2.so.16 "${OUT}/lib/"
65cp /lib/x86_64-linux-gnu/libjson-c.so.* "${OUT}/lib/"
66