2018-01-14 00:51:07 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
#
|
|
|
|
# Copyright 2017 Jonathan Rudenberg
|
|
|
|
#
|
|
|
|
# systemd is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# systemd is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public License
|
|
|
|
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
export LC_CTYPE=C.UTF-8
|
|
|
|
|
2018-03-12 14:59:10 +00:00
|
|
|
export CC=${CC:-clang}
|
|
|
|
export CXX=${CXX:-clang++}
|
|
|
|
clang_version="$($CC --version | sed -nr 's/.*version ([^ ]+?) .*/\1/p' | sed -r 's/-$//')"
|
|
|
|
|
2018-01-16 15:25:43 +00:00
|
|
|
SANITIZER=${SANITIZER:-address -fsanitize-address-use-after-scope}
|
|
|
|
flags="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=$SANITIZER -fsanitize-coverage=trace-pc-guard,trace-cmp"
|
|
|
|
|
2018-03-12 14:59:10 +00:00
|
|
|
clang_lib="/usr/lib64/clang/${clang_version}/lib/linux"
|
|
|
|
[ -d "$clang_lib" ] || clang_lib="/usr/lib/clang/${clang_version}/lib/linux"
|
|
|
|
|
2018-01-16 15:25:43 +00:00
|
|
|
export CFLAGS=${CFLAGS:-$flags}
|
|
|
|
export CXXFLAGS=${CXXFLAGS:-$flags}
|
2018-03-12 14:59:10 +00:00
|
|
|
export LDFLAGS=${LDFLAGS:--L${clang_lib}}
|
|
|
|
|
2018-01-16 15:25:43 +00:00
|
|
|
export WORK=${WORK:-$(pwd)}
|
|
|
|
export OUT=${OUT:-$(pwd)/out}
|
|
|
|
mkdir -p $OUT
|
|
|
|
|
2018-01-16 13:36:56 +00:00
|
|
|
build=$WORK/build
|
|
|
|
rm -rf $build
|
|
|
|
mkdir -p $build
|
|
|
|
|
2018-01-16 15:25:43 +00:00
|
|
|
fuzzflag="oss-fuzz=true"
|
|
|
|
if [ -z "$FUZZING_ENGINE" ]; then
|
|
|
|
fuzzflag="llvm-fuzz=true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
meson $build -D$fuzzflag -Db_lundef=false
|
2018-01-16 13:36:56 +00:00
|
|
|
ninja -C $build fuzzers
|
2018-01-14 00:51:07 +00:00
|
|
|
|
2018-01-20 00:44:56 +00:00
|
|
|
for d in "$(dirname "$0")/../test/fuzz-corpus/"*; do
|
|
|
|
zip -jqr $OUT/fuzz-$(basename "$d")_seed_corpus.zip "$d"
|
|
|
|
done
|
|
|
|
|
|
|
|
# get fuzz-dns-packet corpus
|
2018-01-16 13:36:56 +00:00
|
|
|
df=$build/dns-fuzzing
|
2018-01-14 00:51:07 +00:00
|
|
|
git clone --depth 1 https://github.com/CZ-NIC/dns-fuzzing $df
|
|
|
|
zip -jqr $OUT/fuzz-dns-packet_seed_corpus.zip $df/packet
|
|
|
|
|
|
|
|
mkdir -p $OUT/src/shared
|
2018-01-16 13:36:56 +00:00
|
|
|
mv $build/src/shared/libsystemd-shared-*.so $OUT/src/shared
|
2018-01-14 00:51:07 +00:00
|
|
|
|
2018-01-16 13:36:56 +00:00
|
|
|
find $build -maxdepth 1 -type f -executable -name "fuzz-*" -exec mv {} $OUT \;
|
2018-01-16 15:25:43 +00:00
|
|
|
cp src/fuzz/*.options $OUT
|