2020-03-04 17:35:06 +08:00
|
|
|
#!/usr/bin/env bash
|
2018-01-14 08:51:07 +08:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
|
|
|
|
set -ex
|
|
|
|
|
|
|
|
export LC_CTYPE=C.UTF-8
|
|
|
|
|
2018-03-12 22:59:10 +08: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 23:25:43 +08:00
|
|
|
SANITIZER=${SANITIZER:-address -fsanitize-address-use-after-scope}
|
2019-05-09 06:03:41 +08:00
|
|
|
flags="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=$SANITIZER"
|
2018-01-16 23:25:43 +08:00
|
|
|
|
2018-03-12 22:59:10 +08: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 23:25:43 +08:00
|
|
|
export CFLAGS=${CFLAGS:-$flags}
|
|
|
|
export CXXFLAGS=${CXXFLAGS:-$flags}
|
2018-03-12 22:59:10 +08:00
|
|
|
export LDFLAGS=${LDFLAGS:--L${clang_lib}}
|
|
|
|
|
2018-01-16 23:25:43 +08:00
|
|
|
export WORK=${WORK:-$(pwd)}
|
|
|
|
export OUT=${OUT:-$(pwd)/out}
|
|
|
|
mkdir -p $OUT
|
|
|
|
|
2018-01-16 21:36:56 +08:00
|
|
|
build=$WORK/build
|
|
|
|
rm -rf $build
|
|
|
|
mkdir -p $build
|
|
|
|
|
2018-01-16 23:25:43 +08:00
|
|
|
if [ -z "$FUZZING_ENGINE" ]; then
|
scripts: use 4 space indentation
We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed.
4 sp was the most common, in particular the majority of scripts under test/
used that. Let's standarize on 4 sp, because many commandlines are long and
there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp
also seems to be the default indentation, so this will make it less likely
that people will mess up if they don't load the editor config. (I think people
often use vi, and vi has no support to load project-wide configuration
automatically. We distribute a .vimrc file, but it is not loaded by default,
and even the instructions in it seem to discourage its use for security
reasons.)
Also remove the few vim config lines that were left. We should either have them
on all files, or none.
Also remove some strange stuff like '#!/bin/env bash', yikes.
2019-04-04 20:10:42 +08:00
|
|
|
fuzzflag="llvm-fuzz=true"
|
2020-05-21 14:20:01 +08:00
|
|
|
else
|
|
|
|
fuzzflag="oss-fuzz=true"
|
|
|
|
if [[ "$SANITIZER" == undefined ]]; then
|
|
|
|
UBSAN_FLAGS="-fsanitize=pointer-overflow -fno-sanitize-recover=pointer-overflow"
|
|
|
|
CFLAGS="$CFLAGS $UBSAN_FLAGS"
|
|
|
|
CXXFLAGS="$CXXFLAGS $UBSAN_FLAGS"
|
|
|
|
fi
|
2018-01-16 23:25:43 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
meson $build -D$fuzzflag -Db_lundef=false
|
2019-05-09 06:03:41 +08:00
|
|
|
ninja -v -C $build fuzzers
|
2018-01-14 08:51:07 +08:00
|
|
|
|
2018-07-07 23:43:40 +08:00
|
|
|
# The seed corpus is a separate flat archive for each fuzzer,
|
|
|
|
# with a fixed name ${fuzzer}_seed_corpus.zip.
|
|
|
|
for d in "$(dirname "$0")/../test/fuzz/fuzz-"*; do
|
scripts: use 4 space indentation
We had all kinds of indentation: 2 sp, 3 sp, 4 sp, 8 sp, and mixed.
4 sp was the most common, in particular the majority of scripts under test/
used that. Let's standarize on 4 sp, because many commandlines are long and
there's a lot of nesting, and with 8sp indentation less stuff fits. 4 sp
also seems to be the default indentation, so this will make it less likely
that people will mess up if they don't load the editor config. (I think people
often use vi, and vi has no support to load project-wide configuration
automatically. We distribute a .vimrc file, but it is not loaded by default,
and even the instructions in it seem to discourage its use for security
reasons.)
Also remove the few vim config lines that were left. We should either have them
on all files, or none.
Also remove some strange stuff like '#!/bin/env bash', yikes.
2019-04-04 20:10:42 +08:00
|
|
|
zip -jqr $OUT/$(basename "$d")_seed_corpus.zip "$d"
|
2018-01-20 08:44:56 +08:00
|
|
|
done
|
|
|
|
|
|
|
|
# get fuzz-dns-packet corpus
|
2018-01-16 21:36:56 +08:00
|
|
|
df=$build/dns-fuzzing
|
2018-01-14 08:51:07 +08:00
|
|
|
git clone --depth 1 https://github.com/CZ-NIC/dns-fuzzing $df
|
|
|
|
zip -jqr $OUT/fuzz-dns-packet_seed_corpus.zip $df/packet
|
|
|
|
|
2018-08-16 10:06:35 +08:00
|
|
|
install -Dt $OUT/src/shared/ $build/src/shared/libsystemd-shared-*.so
|
2018-01-14 08:51:07 +08:00
|
|
|
|
2018-08-01 18:25:26 +08:00
|
|
|
wget -O $OUT/fuzz-json.dict https://raw.githubusercontent.com/rc0r/afl-fuzz/master/dictionaries/json.dict
|
|
|
|
|
2018-01-16 21:36:56 +08:00
|
|
|
find $build -maxdepth 1 -type f -executable -name "fuzz-*" -exec mv {} $OUT \;
|
2018-11-07 02:51:45 +08:00
|
|
|
find src -type f -name "fuzz-*.dict" -exec cp {} $OUT \;
|
2018-01-16 23:25:43 +08:00
|
|
|
cp src/fuzz/*.options $OUT
|