]> git.proxmox.com Git - mirror_lxc.git/blame - src/tests/oss-fuzz.sh
ci: stop passing --enable-ubsan
[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
27# -fsanitize=... isn't compatible with -Wl,-no-undefined
28# https://github.com/google/sanitizers/issues/380
29sed -i 's/-Wl,-no-undefined *\\/\\/' src/lxc/Makefile.am
30
31# AFL++ and hoggfuzz are both incompatible with lto=thin apparently
32sed -i '/-flto=thin/d' configure.ac
33
34# turn off the libutil dependency
35sed -i 's/^AC_CHECK_LIB(util/#/' configure.ac
36
37./autogen.sh
38./configure \
39 --disable-tools \
40 --disable-commands \
41 --disable-apparmor \
42 --disable-openssl \
43 --disable-selinux \
44 --disable-seccomp \
45 --disable-capabilities
46
47make -j$(nproc)
48
49$CC -c -o fuzz-lxc-config-read.o $CFLAGS -Isrc -Isrc/lxc src/tests/fuzz-lxc-config-read.c
50$CXX $CXXFLAGS $LIB_FUZZING_ENGINE fuzz-lxc-config-read.o src/lxc/.libs/liblxc.a -o $OUT/fuzz-lxc-config-read
51
593f13bf
EV
52perl -lne 'if (/config_jump_table\[\]\s*=/../^}/) { /"([^"]+)"/ && print "$1=" }' src/lxc/confile.c >doc/examples/keys.conf
53[[ -s doc/examples/keys.conf ]]
54
55perl -lne 'if (/config_jump_table_net\[\]\s*=/../^}/) { /"([^"]+)"/ && print "lxc.net.$1=" }' src/lxc/confile.c >doc/examples/lxc-net-keys.conf
56[[ -s doc/examples/lxc-net-keys.conf ]]
57
dec64820 58zip -r $OUT/fuzz-lxc-config-read_seed_corpus.zip doc/examples