• 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
18CFLAGS="${CFLAGS} -pthread" CXXFLAGS="${CXXFLAGS} -pthread" \
19    ./configure --prefix=$(pwd)/build/install-root \
20                --build-type=debug \
21                --generator=Ninja \
22                --enable-fuzzers \
23                --disable-python \
24                --disable-zeekctl \
25                --disable-auxtools \
26                --disable-broker-tests
27
28
29cd build
30ninja install
31
32cp -R ./install-root/share/zeek ${OUT}/oss-fuzz-zeek-scripts
33
34fuzzers=$(find . -name 'zeek-*-fuzzer')
35fuzzer_count=1
36
37function copy_lib
38    {
39    local fuzzer_path=$1
40    local lib=$2
41    cp $(ldd ${fuzzer_path} | grep "${lib}" | awk '{ print $3 }') ${OUT}/lib
42    }
43
44for f in ${fuzzers}; do
45    fuzzer_exe=$(basename ${f})
46    fuzzer_name=$(echo ${fuzzer_exe} | sed 's/zeek-\(.*\)-fuzzer/\1/g')
47
48    cp ${f} ${OUT}/
49
50    # Set up run-time dependency libraries
51    if [[ "${fuzzer_count}" -eq "1" ]]; then
52        mkdir -p ${OUT}/lib
53        zeek_libs=$(ldd ${f} | grep 'zeek/build' | awk '{ print $1 }' )
54
55        for lib in ${zeek_libs}; do
56            copy_lib ${f} ${lib}
57        done
58
59        copy_lib ${f} libpcap
60        copy_lib ${f} libssl
61        copy_lib ${f} libcrypto
62        copy_lib ${f} libz
63        copy_lib ${f} libmaxminddb
64    fi
65
66    patchelf --set-rpath '$ORIGIN/lib' ${OUT}/${fuzzer_exe}
67
68    if [[ -e ../src/fuzzers/${fuzzer_name}.dict ]]; then
69        cp ../src/fuzzers/${fuzzer_name}.dict ${OUT}/${fuzzer_exe}.dict
70    fi
71
72    if [[ -e ../src/fuzzers/${fuzzer_name}-corpus.zip ]]; then
73        cp ../src/fuzzers/${fuzzer_name}-corpus.zip ${OUT}/${fuzzer_exe}_seed_corpus.zip
74    fi
75
76    fuzzer_count=$((fuzzer_count + 1))
77done
78
79if [ "${SANITIZER}" = "coverage" ]; then
80  # Normally, base-builder/compile copies sources for use in coverage reports,
81  # but its use of `cp -rL` omits the "zeek -> ." symlink used by #includes,
82  # causing the coverage build to fail.
83  mkdir -p $OUT/$(basename $SRC)
84  cp -r $SRC/zeek $OUT/$(basename $SRC)/zeek
85fi
86