Skip to content

Commit fec3ea7

Browse files
committed
ci: add libFuzzer job
The job builds with clang, ASan and UBSan, and runs every fuzz target on an empty corpus for 10000 runs or 20 seconds, whichever comes first. It passes -len_control=0, so inputs have full length from the first run. Otherwise libFuzzer lengthens them slowly, and in 10000 runs they stay under 100 bytes, too short for the musig, ellswift and silentpayments targets to reach their last checks. CFLAGS carry -fsanitize=fuzzer-no-link, not -fsanitize=fuzzer: on Linux clang links the latter as a whole archive, libFuzzer's main included, into every program it links, which clashes with the main of configure's checks, the tests and the examples. Assisted-by: my usual tools (LLM, Internet, computer). Mistakes are mine. Signed-off-by: Ferdinando Ametrano <ferdinando@ametrano.net>
1 parent 2bfecf6 commit fec3ea7

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

‎.github/workflows/ci.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ env:
4848
SYMBOL_CHECK: 'yes'
4949
# Compile and run the examples.
5050
EXAMPLES: 'yes'
51+
FUZZ: 'no'
5152
# Disable Docker build summary generation.
5253
# See https://github.com/docker/build-push-action/blob/master/README.md#environment-variables.
5354
DOCKER_BUILD_SUMMARY: false
@@ -328,6 +329,34 @@ jobs:
328329
- *CI_SCRIPT_IN_DOCKER
329330
- *PRINT_LOGS
330331

332+
fuzz_debian:
333+
name: "libFuzzer"
334+
runs-on: ubuntu-latest
335+
needs: docker_cache
336+
337+
strategy:
338+
matrix:
339+
configuration:
340+
- env_vars: {}
341+
342+
env:
343+
CC: 'clang'
344+
ASM: 'auto'
345+
FUZZ: 'yes'
346+
CTIMETESTS: 'no'
347+
CFLAGS: '-fsanitize=fuzzer-no-link,address,undefined -g'
348+
UBSAN_OPTIONS: 'print_stacktrace=1:halt_on_error=1'
349+
ASAN_OPTIONS: 'strict_string_checks=1:detect_stack_use_after_return=1:detect_leaks=1'
350+
LSAN_OPTIONS: 'use_unaligned=1'
351+
SECP256K1_TEST_ITERS: 2
352+
BENCH: 'no'
353+
SYMBOL_CHECK: 'no'
354+
355+
steps:
356+
- *CHECKOUT
357+
- *CI_SCRIPT_IN_DOCKER
358+
- *PRINT_LOGS
359+
331360
msan_debian:
332361
name: "MSan"
333362
runs-on: ubuntu-latest

‎ci/ci.sh‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ print_environment() {
1515
ECMULTWINDOW ECMULTGENKB ASM WIDEMUL WITH_VALGRIND EXTRAFLAGS \
1616
EXPERIMENTAL ECDH RECOVERY EXTRAKEYS MUSIG SCHNORRSIG ELLSWIFT SILENTPAYMENTS \
1717
SECP256K1_TEST_ITERS BENCH SECP256K1_BENCH_ITERS CTIMETESTS SYMBOL_CHECK \
18-
EXAMPLES \
18+
EXAMPLES FUZZ \
1919
HOST WRAPPER_CMD \
2020
CC CFLAGS CPPFLAGS AR NM \
2121
UBSAN_OPTIONS ASAN_OPTIONS LSAN_OPTIONS
@@ -66,6 +66,7 @@ fi
6666
--enable-module-musig="$MUSIG" \
6767
--enable-module-silentpayments="$SILENTPAYMENTS" \
6868
--enable-examples="$EXAMPLES" \
69+
--enable-fuzz="$FUZZ" \
6970
--enable-ctime-tests="$CTIMETESTS" \
7071
--with-valgrind="$WITH_VALGRIND" \
7172
--host="$HOST" $EXTRAFLAGS
@@ -136,6 +137,16 @@ then
136137
fi
137138
fi
138139

140+
if [ "$FUZZ" = "yes" ]
141+
then
142+
# With FUZZ empty, ./fuzz lists its targets after a header line.
143+
targets=$(FUZZ='' ./fuzz 2>&1 | tail -n +2)
144+
test -n "$targets"
145+
for target in $targets; do
146+
FUZZ="$target" $EXEC ./fuzz -runs=10000 -max_total_time=20 -len_control=0 >> fuzz.log 2>&1
147+
done
148+
fi
149+
139150
# Rebuild precomputed files (if not cross-compiling).
140151
if [ -z "$HOST" ]
141152
then

0 commit comments

Comments
 (0)