]> git.ipfire.org Git - thirdparty/systemd.git/blame_incremental - tools/oss-fuzz.sh
fuzzit: get MSan to track origins
[thirdparty/systemd.git] / tools / oss-fuzz.sh
... / ...
CommitLineData
1#!/bin/bash
2# SPDX-License-Identifier: LGPL-2.1+
3
4set -ex
5
6export LC_CTYPE=C.UTF-8
7
8export CC=${CC:-clang}
9export CXX=${CXX:-clang++}
10clang_version="$($CC --version | sed -nr 's/.*version ([^ ]+?) .*/\1/p' | sed -r 's/-$//')"
11
12SANITIZER=${SANITIZER:-address -fsanitize-address-use-after-scope}
13flags="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=$SANITIZER"
14
15clang_lib="/usr/lib64/clang/${clang_version}/lib/linux"
16[ -d "$clang_lib" ] || clang_lib="/usr/lib/clang/${clang_version}/lib/linux"
17
18export CFLAGS=${CFLAGS:-$flags}
19export CXXFLAGS=${CXXFLAGS:-$flags}
20export LDFLAGS=${LDFLAGS:--L${clang_lib}}
21
22export WORK=${WORK:-$(pwd)}
23export OUT=${OUT:-$(pwd)/out}
24mkdir -p $OUT
25
26build=$WORK/build
27rm -rf $build
28mkdir -p $build
29
30fuzzflag="oss-fuzz=true"
31if [ -z "$FUZZING_ENGINE" ]; then
32 fuzzflag="llvm-fuzz=true"
33fi
34
35meson $build -D$fuzzflag -Db_lundef=false
36ninja -v -C $build fuzzers
37
38# The seed corpus is a separate flat archive for each fuzzer,
39# with a fixed name ${fuzzer}_seed_corpus.zip.
40for d in "$(dirname "$0")/../test/fuzz/fuzz-"*; do
41 zip -jqr $OUT/$(basename "$d")_seed_corpus.zip "$d"
42done
43
44# get fuzz-dns-packet corpus
45df=$build/dns-fuzzing
46git clone --depth 1 https://github.com/CZ-NIC/dns-fuzzing $df
47zip -jqr $OUT/fuzz-dns-packet_seed_corpus.zip $df/packet
48
49install -Dt $OUT/src/shared/ $build/src/shared/libsystemd-shared-*.so
50
51wget -O $OUT/fuzz-json_seed_corpus.zip https://storage.googleapis.com/skia-fuzzer/oss-fuzz/skjson_seed_corpus.zip
52wget -O $OUT/fuzz-json.dict https://raw.githubusercontent.com/rc0r/afl-fuzz/master/dictionaries/json.dict
53
54find $build -maxdepth 1 -type f -executable -name "fuzz-*" -exec mv {} $OUT \;
55find src -type f -name "fuzz-*.dict" -exec cp {} $OUT \;
56cp src/fuzz/*.options $OUT