]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/oss-fuzz.sh
tests: use busybox in lxc-test-unpriv
[mirror_lxc.git] / src / tests / oss-fuzz.sh
CommitLineData
dec64820
EV
1#!/bin/bash
2
3set -ex
4
5export SANITIZER=${SANITIZER:-address}
6flags="-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
dec64820
EV
7coverage_flags="-fsanitize=fuzzer-no-link"
8
745d6048
EV
9sanitizer_flags="-fsanitize=address -fsanitize-address-use-after-scope"
10if [[ "$SANITIZER" == "undefined" ]]; then
11 sanitizer_flags="-fsanitize=undefined"
12elif [[ "$SANITIZER" == "memory" ]]; then
13 sanitizer_flags="-fsanitize=memory -fsanitize-memory-track-origins"
14fi
15
dec64820
EV
16export CC=${CC:-clang}
17export CFLAGS=${CFLAGS:-$flags $sanitizer_flags $coverage_flags}
18
19export CXX=${CXX:-clang++}
20export CXXFLAGS=${CXXFLAGS:-$flags $sanitizer_flags $coverage_flags}
21
22export OUT=${OUT:-$(pwd)/out}
23mkdir -p $OUT
24
25export LIB_FUZZING_ENGINE=${LIB_FUZZING_ENGINE:--fsanitize=fuzzer}
26
dec64820
EV
27# turn off the libutil dependency
28sed -i 's/^AC_CHECK_LIB(util/#/' configure.ac
29
30./autogen.sh
31./configure \
32 --disable-tools \
33 --disable-commands \
34 --disable-apparmor \
35 --disable-openssl \
36 --disable-selinux \
37 --disable-seccomp \
49ffe5da 38 --disable-capabilities \
1667e14e
EV
39 --disable-no-undefined \
40 --enable-tests \
41 --enable-fuzzers
dec64820
EV
42
43make -j$(nproc)
44
e8694d9a
EV
45for fuzz_target_source in src/tests/fuzz-lxc*.c; do
46 fuzz_target_name=$(basename "$fuzz_target_source" ".c")
1667e14e 47 cp "src/tests/$fuzz_target_name" "$OUT"
e8694d9a 48done
dec64820 49
593f13bf
EV
50perl -lne 'if (/config_jump_table\[\]\s*=/../^}/) { /"([^"]+)"/ && print "$1=" }' src/lxc/confile.c >doc/examples/keys.conf
51[[ -s doc/examples/keys.conf ]]
52
53perl -lne 'if (/config_jump_table_net\[\]\s*=/../^}/) { /"([^"]+)"/ && print "lxc.net.$1=" }' src/lxc/confile.c >doc/examples/lxc-net-keys.conf
54[[ -s doc/examples/lxc-net-keys.conf ]]
55
dec64820 56zip -r $OUT/fuzz-lxc-config-read_seed_corpus.zip doc/examples
e8694d9a
EV
57
58mkdir fuzz-lxc-define-load_seed_corpus
59perl -lne '/([^=]+)/ && print "printf $1= >fuzz-lxc-define-load_seed_corpus/$1"' doc/examples/{keys,lxc-net-keys}.conf | bash
60zip -r $OUT/fuzz-lxc-define-load_seed_corpus.zip fuzz-lxc-define-load_seed_corpus