• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 Google LLC
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
18git apply  --ignore-space-change --ignore-whitespace $SRC/patch.diff
19
20function copy_lib
21    {
22    local fuzzer_path=$1
23    local lib=$2
24    cp $(ldd ${fuzzer_path} | grep "${lib}" | awk '{ print $3 }') ${OUT}/lib
25    }
26
27mkdir -p $OUT/lib
28
29if [ "$SANITIZER" = "coverage" ]
30then
31    # so that we do not get openssl
32    export CXXFLAGS="$CXXFLAGS -fsanitize=fuzzer-no-link,address"
33    export CFLAGS="$CFLAGS -fsanitize=fuzzer-no-link,address"
34fi
35
36# build project
37./bootstrap
38# java fails with Source option 6 is no longer supported. Use 7 or later.
39./configure --disable-java --enable-fuzzing --disable-shared
40
41# patch bluez
42sed -i 's/sys\/socket.h>/sys\/socket.h>\n#include <linux\/sockios.h>/g' ./third_party/bluez/repo/tools/l2test.c
43sed -i 's/sys\/stat.h>/sys\/stat.h>\n#include <linux\/sockios.h>/g' ./third_party/bluez/repo/tools/rctest.c
44
45# OpenSSL now declares RAND_bytes so we must patch
46find ./src/test-apps/fuzz/ -name "FuzzP*.cpp" -exec sed -i 's/RAND_bytes/RAND_bytes2/g' {} \;
47
48make -j$(nproc)
49
50find src/test-apps/fuzz/ -type f -executable -name "Fuzz*" | while read i; do
51    patchelf --set-rpath '$ORIGIN/lib' ${i}
52    copy_lib ${i} libglib
53    copy_lib ${i} libdbus
54    cp ${i} $OUT/
55done
56
57# build corpus
58ls $SRC/openweave-core/src/test-apps/fuzz/corpus/ | while read f; do
59    zip -j $OUT/${f}_seed_corpus.zip $SRC/openweave-core/src/test-apps/fuzz/corpus/${f}/*;
60done
61
62cd $OUT/
63ls *_seed_corpus.zip | grep PASE | while read c; do
64    cp $c Fuzz$c;
65done
66
67