mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-06 07:34:21 +01:00
build: introduce a fuzzing mode
This adds a new configuration, --enable-fuzzing (which is more than welcome to be coupled with --enable-address-sanitizer), to pass the fuzzer sanitizer argument when compiling objects. This allows libfuzzer to actually be able "to fuzz" by detecting coverage and be smart when mutating inputs. As libfuzzer brings its own ~~fees~~ main(), we compile objects with fsanitize=fuzzer-no-link, and special-case the linkage of the fuzz targets. A "lib" is added to abstract out the interface to the fuzzing tool used. This allow us to use the same targets to fuzz using AFL, hongfuzz or w/e by adding their entrypoints into libfuzz. (h/t to practicalswift who introduced this for bitcoin-core, which i mimiced) Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
committed by
Christian Decker
parent
ede5f5be3c
commit
62b54d0125
17
configure
vendored
17
configure
vendored
@@ -120,6 +120,7 @@ set_defaults()
|
||||
CONFIGURATOR_CC=${CONFIGURATOR_CC-$CC}
|
||||
VALGRIND=${VALGRIND:-$(default_valgrind_setting)}
|
||||
TEST_NETWORK=${TEST_NETWORK:-regtest}
|
||||
FUZZING=${FUZZING:-0}
|
||||
}
|
||||
|
||||
usage()
|
||||
@@ -155,6 +156,7 @@ usage()
|
||||
echo " Static link sqlite3, gmp and zlib libraries"
|
||||
usage_with_default "--enable/disable-address-sanitizer" "$ASAN" "enable" "disable"
|
||||
echo " Compile with address-sanitizer"
|
||||
usage_with_default "--enable/disable-fuzzing" "$FUZZING" "enable" "disable"
|
||||
exit 1
|
||||
}
|
||||
|
||||
@@ -206,6 +208,8 @@ for opt in "$@"; do
|
||||
--disable-static) STATIC=0;;
|
||||
--enable-address-sanitizer) ASAN=1;;
|
||||
--disable-address-sanitizer) ASAN=0;;
|
||||
--enable-fuzzing) FUZZING=1;;
|
||||
--disable-fuzzing) FUZZING=0;;
|
||||
--help|-h) usage;;
|
||||
*)
|
||||
echo "Unknown option '$opt'" >&2
|
||||
@@ -229,6 +233,18 @@ if [ "$ASAN" = "1" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$FUZZING" = "1" ]; then
|
||||
case "$CC" in
|
||||
(*"clang"*)
|
||||
;;
|
||||
(*)
|
||||
echo "Fuzzing is currently only supported with clang."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
||||
SQLITE3_CFLAGS=""
|
||||
SQLITE3_LDLIBS="-lsqlite3"
|
||||
if command -v "${PKG_CONFIG}" >/dev/null; then
|
||||
@@ -400,6 +416,7 @@ add_var ASAN "$ASAN"
|
||||
add_var TEST_NETWORK "$TEST_NETWORK"
|
||||
add_var HAVE_PYTHON3_MAKO "$HAVE_PYTHON3_MAKO"
|
||||
add_var SHA256SUM "$SHA256SUM"
|
||||
add_var FUZZING "$FUZZING"
|
||||
|
||||
# Hack to avoid sha256 name clash with libwally: will be fixed when that
|
||||
# becomes a standalone shared lib.
|
||||
|
||||
Reference in New Issue
Block a user