• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2017 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
19# Compile and install dependencies for static linking
20# Cribbed from projects/wget2, thanks rockdaboot@gmail.com
21
22export DEPS_PATH=$SRC/knot_deps
23export PKG_CONFIG_PATH=$DEPS_PATH/lib64/pkgconfig:$DEPS_PATH/lib/pkgconfig
24export CPPFLAGS="-I$DEPS_PATH/include"
25export LDFLAGS="-L$DEPS_PATH/lib"
26export GNULIB_SRCDIR=$SRC/gnulib
27export GNULIB_TOOL=$SRC/gnulib/gnulib-tool
28
29cd $SRC/libunistring
30./autogen.sh
31./configure --enable-static --disable-shared --prefix=$DEPS_PATH
32make -j$(nproc)
33make install
34
35GNUTLS_CONFIGURE_FLAGS=""
36NETTLE_CONFIGURE_FLAGS=""
37if [[ $CFLAGS = *sanitize=memory* ]]; then
38  GNUTLS_CONFIGURE_FLAGS="--disable-hardware-acceleration"
39  NETTLE_CONFIGURE_FLAGS="--disable-assembler --disable-fat"
40fi
41
42cd $SRC/nettle
43bash .bootstrap
44./configure --enable-mini-gmp --enable-static --disable-shared --disable-documentation --prefix=$DEPS_PATH $NETTLE_CONFIGURE_FLAGS
45( make -j$(nproc) || make -j$(nproc) ) && make install
46
47cd $SRC/gnutls
48touch .submodule.stamp
49./bootstrap
50GNUTLS_CFLAGS=`echo $CFLAGS|sed s/-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION//`
51LIBS="-lunistring" \
52CFLAGS="$GNUTLS_CFLAGS" \
53./configure --with-nettle-mini --enable-gcc-warnings --enable-static --disable-shared --with-included-libtasn1 \
54    --with-included-unistring --without-p11-kit --disable-doc --disable-tests --disable-tools --disable-cxx \
55    --disable-maintainer-mode --disable-libdane --disable-gcc-warnings --prefix=$DEPS_PATH $GNUTLS_CONFIGURE_FLAGS
56make -j$(nproc)
57make install
58
59cd $SRC/lmdb/libraries/liblmdb
60make -j$(nproc)
61make install
62
63# Compile knot, install fuzzers to $OUT
64
65cd $SRC/knot-dns
66sed -i 's/-llmdb/-Wl,-Bstatic,-llmdb,-Bdynamic/' configure.ac
67autoreconf -if
68./configure --with-oss-fuzz=yes --disable-shared --enable-static --disable-daemon --disable-utilities --disable-documentation \
69    --disable-fastparser --disable-modules
70make -j$(nproc)
71cd $SRC/knot-dns/tests-fuzz
72make check
73/bin/bash ../libtool   --mode=install /usr/bin/install -c fuzz_packet fuzz_zscanner fuzz_dname_to_str fuzz_dname_from_str "$OUT"
74
75# Set up fuzzing seeds
76
77git submodule update --init -- ./fuzz_packet.in
78git submodule update --init -- ./fuzz_zscanner.in
79# ./fuzz_dname_to_str.in/ and ./fuzz_dname_from_str.in/ are stored in the base repository
80find ./fuzz_packet.in/         -type f -exec zip -u $OUT/fuzz_packet_seed_corpus.zip {} \;
81find ./fuzz_zscanner.in/       -type f -exec zip -u $OUT/fuzz_zscanner_seed_corpus.zip {} \;
82find ./fuzz_dname_to_str.in/   -type f -exec zip -u $OUT/fuzz_dname_to_str_seed_corpus.zip {} \;
83find ./fuzz_dname_from_str.in/ -type f -exec zip -u $OUT/fuzz_dname_from_str_seed_corpus.zip {} \;
84