1#!/bin/bash -eu
2# Copyright 2018 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# remove dependencies on boost's program_options, we don't need it
19# and it won't link because oss-fuzz adds -stdlib=libc++ to the flags,
20# which would require rebuilding boost
21sed -i 's/BOOST_PROGRAM_OPTIONS(\[mt\])//' configure.ac
22sed -i 's/AC_MSG_ERROR(\[Boost Program Options library not found\])/AC_MSG_NOTICE(\[Boost Program Options library not found\])/' configure.ac
23# we also need to disable building as PIE because libFuzzingEngine.a
24# does not appear to be compiled as PIC
25sed -i 's/AC_CC_PIE//' configure.ac
26
27# build fuzzing targets
28autoreconf -vi
29./configure \
30    --without-dynmodules \
31    --with-modules='' \
32    --disable-lua-records \
33    --disable-ixfrdist \
34    --enable-fuzz-targets \
35    --disable-dependency-tracking \
36    --disable-silent-rules || /bin/bash
37cd pdns
38make -j$(nproc) fuzz_targets
39
40# copy the fuzzing target binaries
41cp fuzz_target_* "${OUT}/"
42
43# copy the zones used in the regression tests to the "zones" corpus
44cp ../regression-tests/zones/* ../fuzzing/corpus/zones/
45
46# generate the corpus files
47zip -j "${OUT}/fuzz_target_dnsdistcache_seed_corpus.zip" ../fuzzing/corpus/raw-dns-packets/*
48zip -j "${OUT}/fuzz_target_moadnsparser_seed_corpus.zip" ../fuzzing/corpus/raw-dns-packets/*
49zip -j "${OUT}/fuzz_target_packetcache_seed_corpus.zip" ../fuzzing/corpus/raw-dns-packets/*
50zip -j "${OUT}/fuzz_target_zoneparsertng_seed_corpus.zip" ../fuzzing/corpus/zones/*
51