eBPF-based security platform
testing: prepare the fuzz targets for parsers that log
Daniel Borkmann3c8a5408aeec
diff --git a/Makefile.shirudo b/Makefile.shirudoindex b4716c2b..2d86a771 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -679,14 +679,12 @@ FUZZ_CFLAGS := -O1 -g -std=gnu11 -fno-omit-frame-pointer \-D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE $(INCLUDES) \$(LIBCRYPTO_CFLAGS) $(LIBCURL_CFLAGS) $(ZLIB_CFLAGS)FUZZ_LIBS := $(LIBCRYPTO_LIBS) $(LIBSSL_LIBS) $(LIBCURL_LIBS) $(ZLIB_LIBS)-FUZZ_BASE := util/json.c util/hex.c util/malloc.c util/log.c+FUZZ_BASE := util/json.c util/hex.c util/malloc.c testing/fuzz/log.cFUZZ_OCI := util/bpm_oci.c util/io.c util/seal.c util/crypto_openssl.c \util/tls_openssl.cFUZZ_PACKAGE := util/bpm_package.c util/bpm_tree.c $(FUZZ_OCI)-FUZZ_TARGETS := testing/fuzz/fuzz-json testing/fuzz/fuzz-oci-manifest \- testing/fuzz/fuzz-bpm-index testing/fuzz/fuzz-tree \- testing/fuzz/fuzz-upatch testing/fuzz/fuzz-bpm-tar+FUZZ_TARGETS := $(patsubst %.c,%,$(wildcard testing/fuzz/fuzz-*.c))testing/fuzz/fuzz-json: testing/fuzz/fuzz-json.c $(FUZZ_BASE)testing/fuzz/fuzz-oci-manifest: testing/fuzz/fuzz-oci-manifest.c \diff --git a/testing/fuzz/log.c b/testing/fuzz/log.cnew file mode 100644index 00000000..a8d94661--- /dev/null+++ b/testing/fuzz/log.c@@ -0,0 +1,41 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * util/log.c for the fuzz targets: format each message, then drop it.+ */++#include <stdarg.h>+#include <stdio.h>++#include "log.h"++void shirudo_log_init(void)+{+}++/*+ * A parser rejecting a mutated input logs, millions of times a minute:+ * not to the journal. Formatting still runs, so a message that reads+ * past what it prints is caught.+ */+static void drop(const char *fmt, va_list ap)+{+ char msg[8192];++ vsnprintf(msg, sizeof(msg), fmt, ap);+}++#define PR_DEFINE(name) \+ void name(const char *fmt, ...) \+ { \+ va_list ap; \+ va_start(ap, fmt); \+ drop(fmt, ap); \+ va_end(ap); \+ }++PR_DEFINE(pr_err)+PR_DEFINE(pr_warn)+PR_DEFINE(pr_info)+PR_DEFINE(pr_audit)diff --git a/testing/fuzz/run.sh b/testing/fuzz/run.shindex 84f188e2..a9180c9e 100755--- a/testing/fuzz/run.sh+++ b/testing/fuzz/run.sh@@ -2,9 +2,10 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# testing/fuzz/run.sh -- run each libFuzzer target for the given seconds on-# its seed corpus, keeping what it finds in a scratch directory. A crash-# fails the run and leaves the input that caused it in testing/fuzz.+# testing/fuzz/run.sh -- run the named libFuzzer targets, or one for each+# fuzz-*.c here, for the given seconds on their seed corpora, keeping what+# they find in a scratch directory. A crash fails the run and leaves the+# input that caused it in testing/fuzz.## testing/fuzz/run.sh <seconds> [<target>...]@@ -14,7 +15,10 @@ cd "$(dirname "$0")"seconds=${1:?usage: run.sh <seconds> [<target>...]}shiftif [ $# -eq 0 ]; then- set -- json oci-manifest bpm-index tree upatch bpm-tar+ for c in fuzz-*.c; do+ t=${c#fuzz-}+ set -- "$@" "${t%.c}"+ donefiwork=$(mktemp -d)