2019-06-11 09:25:45 +03:00
#!/bin/bash
set -e
set -x
set -u
2019-09-06 04:44:52 +03:00
# This should help to protect the systemd organization on Fuzzit from forks
# that are activated on Travis CI.
[ [ " $TRAVIS_REPO_SLUG " = "systemd/systemd" ] ] || exit 0
2019-06-11 09:25:45 +03:00
REPO_ROOT = ${ REPO_ROOT :- $( pwd ) }
sudo bash -c "echo 'deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse' >>/etc/apt/sources.list"
sudo apt-get update -y
sudo apt-get build-dep systemd -y
sudo apt-get install -y ninja-build python3-pip python3-setuptools
pip3 install meson
cd $REPO_ROOT
export PATH = " $HOME /.local/bin/: $PATH "
2019-06-15 01:44:27 +03:00
# We use a subset of https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks instead of "undefined"
2019-07-11 16:32:05 +03:00
# because our fuzzers crash with "pointer-overflow" and "float-cast-overflow":
2019-06-17 20:08:48 +03:00
# https://github.com/systemd/systemd/pull/12771#issuecomment-502139157
# https://github.com/systemd/systemd/pull/12812#issuecomment-502780455
2019-06-15 01:44:27 +03:00
# TODO: figure out what to do about unsigned-integer-overflow: https://github.com/google/oss-fuzz/issues/910
2019-07-11 16:32:05 +03:00
export SANITIZER = "address -fsanitize=alignment,array-bounds,bool,bounds,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,unsigned-integer-overflow,vla-bound,vptr -fno-sanitize-recover=alignment,array-bounds,bool,bounds,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,nonnull-attribute,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
2019-06-11 09:25:45 +03:00
tools/oss-fuzz.sh
2019-09-06 20:29:10 +03:00
FUZZING_TYPE = ${ 1 :- regression }
2019-06-11 09:25:45 +03:00
if [ " $TRAVIS_PULL_REQUEST " = "false" ] ; then
2019-06-15 02:16:07 +03:00
FUZZIT_BRANCH = " ${ TRAVIS_BRANCH } "
2019-06-11 09:25:45 +03:00
else
2019-06-15 02:16:07 +03:00
FUZZIT_BRANCH = " PR- ${ TRAVIS_PULL_REQUEST } "
2019-06-11 09:25:45 +03:00
fi
# Because we want Fuzzit to run on every pull-request and Travis/Azure doesnt support encrypted keys
# on pull-request we use a write-only key which is ok for now. maybe there will be a better solution in the future
2019-09-12 13:34:26 +03:00
export FUZZIT_API_KEY = af6992074353998676713818cc6435ef4a750439932dab58b51e9354d6742c54d740a3cd9fc1fc001db82f51734a24bc
2019-07-23 22:50:52 +03:00
FUZZIT_ADDITIONAL_FILES = "./out/src/shared/libsystemd-shared-*.so"
2019-06-15 03:07:17 +03:00
# ASan options are borrowed almost verbatim from OSS-Fuzz
ASAN_OPTIONS = redzone = 32:print_summary= 1:handle_sigill= 1:allocator_release_to_os_interval_ms= 500:print_suppressions= 0:strict_memcmp= 1:allow_user_segv_handler= 0:allocator_may_return_null= 1:use_sigaltstack= 1:handle_sigfpe= 1:handle_sigbus= 1:detect_stack_use_after_return= 1:alloc_dealloc_mismatch= 0:detect_leaks= 1:print_scariness= 1:max_uar_stack_size_log= 16:handle_abort= 1:check_malloc_usable_size= 0:quarantine_size_mb= 64:detect_odr_violation= 0:handle_segv= 1:fast_unwind_on_fatal= 0
2019-06-15 02:16:07 +03:00
UBSAN_OPTIONS = print_stacktrace = 1:print_summary= 1:halt_on_error= 1:silence_unsigned_overflow= 1
2019-09-06 20:29:10 +03:00
FUZZIT_ARGS = " --type ${ FUZZING_TYPE } --branch ${ FUZZIT_BRANCH } --revision ${ TRAVIS_COMMIT } -e ASAN_OPTIONS= ${ ASAN_OPTIONS } -e UBSAN_OPTIONS= ${ UBSAN_OPTIONS } "
wget -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/latest/download/fuzzit_Linux_x86_64
2019-06-11 09:25:45 +03:00
chmod +x fuzzit
2019-09-06 20:29:10 +03:00
find out/ -maxdepth 1 -name 'fuzz-*' -executable -type f -exec basename '{}' \; | xargs --verbose -n1 -I%FUZZER% ./fuzzit create job ${ FUZZIT_ARGS } %FUZZER%-asan-ubsan out/%FUZZER% ${ FUZZIT_ADDITIONAL_FILES }
2019-08-08 00:45:19 +03:00
2019-08-08 21:30:44 +03:00
export SANITIZER = "memory -fsanitize-memory-track-origins"
2019-08-08 00:45:19 +03:00
FUZZIT_ARGS = " --type ${ FUZZING_TYPE } --branch ${ FUZZIT_BRANCH } --revision ${ TRAVIS_COMMIT } "
tools/oss-fuzz.sh
2019-09-06 20:29:10 +03:00
find out/ -maxdepth 1 -name 'fuzz-*' -executable -type f -exec basename '{}' \; | xargs --verbose -n1 -I%FUZZER% ./fuzzit create job ${ FUZZIT_ARGS } %FUZZER%-msan out/%FUZZER% ${ FUZZIT_ADDITIONAL_FILES }