• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2016 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
18export DEPS_PATH=$SRC/deps
19export PKG_CONFIG_PATH=$DEPS_PATH/lib/pkgconfig
20export CPPFLAGS="-I$DEPS_PATH/include"
21export LDFLAGS="-L$DEPS_PATH/lib"
22export GNULIB_SRCDIR=$SRC/gnulib
23
24cd $SRC/libunistring
25./autogen.sh
26ASAN_OPTIONS=detect_leaks=0 \
27  ./configure --enable-static --disable-shared --prefix=$DEPS_PATH
28make -j$(nproc)
29make install
30
31cd $SRC/libidn2
32./bootstrap
33ASAN_OPTIONS=detect_leaks=0 \
34  ./configure --enable-static --disable-shared --disable-doc --disable-gcc-warnings --prefix=$DEPS_PATH
35make -j$(nproc)
36make install
37
38# always disable assembly in GMP to avoid issues due to SIGILL
39#   https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3119
40#   https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=3159
41GMP_CONFIGURE_FLAGS="--disable-assembly --disable-fat"
42
43cd $SRC/gmp
44bash .bootstrap
45ASAN_OPTIONS=detect_leaks=0 \
46  ./configure --disable-shared --prefix=$DEPS_PATH $GMP_CONFIGURE_FLAGS
47make -j$(nproc)
48make install
49
50cd $SRC/libtasn1
51bash bootstrap
52./configure --disable-gcc-warnings --disable-gtk-doc --disable-gtk-doc-pdf --disable-doc \
53  --disable-shared --enable-static --prefix=$DEPS_PATH
54make -j$(nproc)
55make install
56
57NETTLE_CONFIGURE_FLAGS=""
58if [[ $CFLAGS = *sanitize=memory* ]]; then
59  NETTLE_CONFIGURE_FLAGS="--disable-assembler --disable-fat"
60fi
61cd $SRC/nettle
62bash .bootstrap
63ASAN_OPTIONS=detect_leaks=0 \
64  ./configure --enable-static --disable-shared --disable-documentation --prefix=$DEPS_PATH $NETTLE_CONFIGURE_FLAGS
65( make -j$(nproc) || make -j$(nproc) ) && make install
66if test $? != 0; then
67  echo "Failed to compile nettle"
68  exit 1
69fi
70
71
72GNUTLS_CONFIGURE_FLAGS=""
73if [[ $CFLAGS = *sanitize=memory* ]]; then
74  GNUTLS_CONFIGURE_FLAGS="--disable-hardware-acceleration"
75fi
76cd $SRC/gnutls
77./bootstrap
78ASAN_OPTIONS=detect_leaks=0 LIBS="-lunistring" CXXFLAGS="$CXXFLAGS -L$DEPS_PATH/lib" \
79  ./configure --enable-fuzzer-target --disable-gcc-warnings --enable-static --disable-shared --disable-doc --disable-tests \
80    --disable-tools --disable-cxx --disable-maintainer-mode --disable-libdane --without-p11-kit \
81    --disable-full-test-suite $GNUTLS_CONFIGURE_FLAGS
82
83# Do not use the syscall interface for randomness in oss-fuzz, it seems
84# to confuse memory sanitizer.
85sed -i 's|include <sys/syscall.h>|include <sys/syscall.h>\n#undef SYS_getrandom|' lib/nettle/sysrng-linux.c
86
87make -j$(nproc) -C gl
88make -j$(nproc) -C lib
89
90cd fuzz
91make oss-fuzz
92find . -name '*_fuzzer' -exec cp -v '{}' $OUT ';'
93find . -name '*_fuzzer.dict' -exec cp -v '{}' $OUT ';'
94find . -name '*_fuzzer.options' -exec cp -v '{}' $OUT ';'
95
96for dir in *_fuzzer.in; do
97    fuzzer=$(basename $dir .in)
98    zip -rj "$OUT/${fuzzer}_seed_corpus.zip" "${dir}/"
99done
100