eBPF-based security platform
testing: fuzz the parsers of input from outside the host
Daniel Borkmann661518b924ba
diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.ymlindex 5858ca21..f6997cc0 100644--- a/.github/workflows/sanitizers.yml+++ b/.github/workflows/sanitizers.yml@@ -89,3 +89,31 @@ jobs:make SANITIZE=address,undefined shirudo-buildmake -C testing SANITIZE=address,undefined test-helpersmake -C testing SANITIZE=address,undefined test-op++ libfuzzer:+ name: libFuzzer+ runs-on: ubuntu-latest++ steps:+ - name: Check out repository+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1++ # The targets need no BPF objects, but the toolchain the other jobs+ # build in comes with the LVH guest.+ - name: Fuzz the parsers of input from outside the host in LVH VM+ uses: cilium/little-vm-helper@f86d344aca812dda5aef167867a9a0a90ca6cca5 # v0.0.31+ with:+ test-name: shirudo-libfuzzer+ image: kind+ image-version: bpf-next-20260603.072225+ kernel-version: bpf-next-main+ host-mount: ${{ github.workspace }}+ images-folder-parent: ${{ github.workspace }}/../lvh+ install-dependencies: true+ cpu: 4+ mem: 8G+ cmd: |+ cd /host+ .github/scripts/vm-toolchain.sh libclang-rt-21-dev+ . build/vm-toolchain.env+ make -C testing fuzz FUZZ_SECONDS=60diff --git a/.gitignore b/.gitignoreindex 39dc6d8e..f61fcfb6 100644--- a/.gitignore+++ b/.gitignore@@ -50,6 +50,11 @@!/testing/helper/test-bpm-key.py!/testing/helper/test-bpm-info.py+# libFuzzer targets and the inputs that crashed them+/testing/fuzz/fuzz-*+!/testing/fuzz/fuzz-*.c+/testing/fuzz/crash-*+# Local config (PLAN.md "Build system": Makefile.config is a committed# probe file that writes the cached config.mk; util/version_id.c is# regenerated every build).diff --git a/AGENTS.md b/AGENTS.mdindex 86152ea7..9b632a53 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -304,6 +304,10 @@ one usually still compiles and passes tests.that runs `shirudo-initrd.service`; `make -C testing test-installer` runs`testing/t1300-installer-e2e.sh`, the installer end to end in a QEMUguest with a vTPM, two reboots included.+- `make -C testing fuzz [FUZZ_SECONDS=60]` runs the libFuzzer targets in+ `testing/fuzz/` for the parsers of input from outside the host, under+ ASan and UBSan, on their seed corpora; CI runs them too. A parser that+ takes such input gets a target there.- `make -C Documentation html-docs` renders `Documentation/*.rst` with docutils in strictmode into `Documentation/output/`; CI runs it on every push, so run itafter touching any document (python3-docutils provides `rst2html`).diff --git a/Documentation/requirements.rst b/Documentation/requirements.rstindex 89e28e88..5d737f4d 100644--- a/Documentation/requirements.rst+++ b/Documentation/requirements.rst@@ -334,3 +334,6 @@ on.module installed, ``t0033-tpm-wire.sh`` also cross-checks the TPMcredential blob it builds against an independent implementation;without it that one check is skipped.+* ``make -C testing fuzz`` builds the parsers' libFuzzer targets with+ ``clang`` and needs its fuzzer and sanitizer runtime+ (``libclang-rt-<version>-dev`` on Debian and Ubuntu).diff --git a/Makefile.shirudo b/Makefile.shirudoindex 470c7154..9fa96912 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -666,6 +666,45 @@ testing/kernel-obs/exec-paths: testing/kernel-obs/exec_paths.ctest-helpers: $(TEST_HELPERS)+# ----- fuzzing ----------------------------------------------------++# libFuzzer targets for the parsers of input from outside the host, built+# with clang from the util sources under ASan and UBSan; make -C testing+# fuzz builds and runs them.+FUZZ_CC ?= clang+FUZZ_CFLAGS := -O1 -g -std=gnu11 -fno-omit-frame-pointer \+ -fsanitize=fuzzer,address,undefined \+ -fno-sanitize-recover=all $(WARNINGS) \+ -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_OCI := util/bpm_oci.c util/io.c util/seal.c util/crypto_openssl.c \+ util/tls_openssl.c+FUZZ_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++testing/fuzz/fuzz-json: testing/fuzz/fuzz-json.c $(FUZZ_BASE)+testing/fuzz/fuzz-oci-manifest: testing/fuzz/fuzz-oci-manifest.c \+ $(FUZZ_BASE) $(FUZZ_OCI)+testing/fuzz/fuzz-bpm-index: testing/fuzz/fuzz-bpm-index.c \+ $(FUZZ_BASE) $(FUZZ_PACKAGE)+testing/fuzz/fuzz-tree: testing/fuzz/fuzz-tree.c $(FUZZ_BASE) \+ util/bpm_tree.c util/crypto_openssl.c+testing/fuzz/fuzz-upatch: testing/fuzz/fuzz-upatch.c $(FUZZ_BASE) \+ util/upatch.c+testing/fuzz/fuzz-bpm-tar: testing/fuzz/fuzz-bpm-tar.c $(FUZZ_BASE) \+ $(FUZZ_PACKAGE)++$(FUZZ_TARGETS): testing/fuzz/fuzz.h+ @printf ' FUZZ $@\n'+ $(Q)$(FUZZ_CC) $(FUZZ_CFLAGS) -o $@ $(filter %.c,$^) $(FUZZ_LIBS)++fuzz-targets: $(FUZZ_TARGETS)+check test: shirudo $(TEST_HELPERS)@printf ' TEST\n'$(Q)cd testing && ./run-tests.shdiff --git a/testing/Makefile b/testing/Makefileindex e87f2f8a..88d11700 100644--- a/testing/Makefile+++ b/testing/Makefile@@ -19,7 +19,7 @@ test-vm-arch = $(shell TEST_VM_ARCH='$(TEST_VM_ARCH)'; \. $(ROOT)/contrib/test-vm-arch.sh && printf '%s' "$$$(1)").DEFAULT_GOAL := help-.PHONY: help clean test-helpers test-op test test-installer bundle test-vm-bundle kernel \+.PHONY: help clean test-helpers test-op fuzz test test-installer bundle test-vm-bundle kernel \bpf-next vm vm-console vm-ssh vm-stop vm-clean test-tgt test-tgt-obs \test-vm test-vm-clean@@ -260,6 +260,15 @@ test-helpers:+$(Q)$(MAKE) -C $(ROOT) config+$(Q)$(MAKE) -C $(ROOT) -f Makefile.shirudo test-helpers+# The parsers of input from outside the host under libFuzzer, each target+# for FUZZ_SECONDS on its seed corpus; needs clang with its fuzzer runtime.+FUZZ_SECONDS ?= 60++fuzz:+ +$(Q)$(MAKE) -C $(ROOT) config+ +$(Q)$(MAKE) -C $(ROOT) -f Makefile.shirudo fuzz-targets+ $(Q)sh $(ROOT)/testing/fuzz/run.sh $(FUZZ_SECONDS)+# The installer end to end: a stock cloud image in QEMU with a vTPM, the# bpf-next kernel packages, tools/gen-initrd/install.sh with a local# target package, two reboots and the production configuration.@@ -281,6 +290,7 @@ help:' make -C testing test' \' make -C testing test-op' \' make -C testing test-helpers' \+ ' make -C testing fuzz [FUZZ_SECONDS=60]' \' make -C testing test-tgt [TEST_VM_INITRD=1]' \' make -C testing test-tgt-obs' \' make -C testing test-installer' \diff --git a/testing/fuzz/corpus/bpm-index/two-packages b/testing/fuzz/corpus/bpm-index/two-packagesnew file mode 100644index 00000000..d79cbe41--- /dev/null+++ b/testing/fuzz/corpus/bpm-index/two-packages@@ -0,0 +1 @@+{"schema":1,"packages":[{"name":"kernel-obs","version":"1.2.3","repository":"oci://registry.example.org/shirudo/kernel-obs","manifest_digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","package_digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","package_size":4096,"signer_fingerprint":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},{"name":"t","version":"0.1.0-rc1","repository":"oci://registry.example.org/t","manifest_digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","package_digest":"sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","package_size":1}]}\ No newline at end of filediff --git a/testing/fuzz/corpus/bpm-tar/beefile.tar.gz b/testing/fuzz/corpus/bpm-tar/beefile.tar.gznew file mode 100644index 00000000..694d0ebeBinary files /dev/null and b/testing/fuzz/corpus/bpm-tar/beefile.tar.gz differdiff --git a/testing/fuzz/corpus/json/all-types b/testing/fuzz/corpus/json/all-typesnew file mode 100644index 00000000..0cf5b6af--- /dev/null+++ b/testing/fuzz/corpus/json/all-types@@ -0,0 +1 @@+{"s":"x","i":-12,"b":true,"o":{"k":"v","n":2},"a":[{"v":"w","o":{"k":"é\n","n":3}},{"v":"z"}],"skip":[1,2.5e3,null,{"x":[]}]}\ No newline at end of filediff --git a/testing/fuzz/corpus/oci-manifest/tree b/testing/fuzz/corpus/oci-manifest/treenew file mode 100644index 00000000..d98d0217--- /dev/null+++ b/testing/fuzz/corpus/oci-manifest/tree@@ -0,0 +1 @@+{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","artifactType":"application/vnd.shirudo.upatch.tree.v2","config":{"mediaType":"application/vnd.oci.empty.v1+json","digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","size":2},"layers":[{"mediaType":"application/vnd.shirudo.upatch.tree.v2+json","digest":"sha256:5c42dbdd9ab41d9e039b890284f7c51a88c11b436fe37998178f83774ebc0600","size":1662},{"mediaType":"application/vnd.shirudo.upatch.tree.signature.v2","digest":"sha256:0b2c5f50178ab64a58b6640f8f4c41544faf0821f25a8e2a47ac4607b1f63190","size":4853}]}\ No newline at end of filediff --git a/testing/fuzz/corpus/oci-manifest/upatch b/testing/fuzz/corpus/oci-manifest/upatchnew file mode 100644index 00000000..53714987--- /dev/null+++ b/testing/fuzz/corpus/oci-manifest/upatch@@ -0,0 +1 @@+{"schemaVersion":2,"mediaType":"application/vnd.oci.image.manifest.v1+json","artifactType":"application/vnd.shirudo.upatch.v1","config":{"mediaType":"application/vnd.oci.empty.v1+json","digest":"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a","size":2},"layers":[{"mediaType":"application/vnd.shirudo.upatch.v1","digest":"sha256:1cf567e0f11ecc074d68a0e5c8cc36758792fe3595bd3c74147e4c7dda84d163","size":9037}],"annotations":{"org.opencontainers.image.title":"t.upatch"}}\ No newline at end of filediff --git a/testing/fuzz/corpus/tree/three-operations b/testing/fuzz/corpus/tree/three-operationsnew file mode 100644index 00000000..61902b18--- /dev/null+++ b/testing/fuzz/corpus/tree/three-operations@@ -0,0 +1 @@+{"schema":2,"tree_id":"t","generation":3,"parent_manifest_digest":"sha256:d1a131e345e29aa6c2e01cb7edb6e8797804d87a0140f7372e9a0ca93fa62320","base":{"seq":0},"operations":[{"seq":1,"op":"add","id":"t","selector":{"architecture":["s390x"]},"artifact":{"repository":"oci://127.0.0.1:5532/ns/tree","manifest_digest":"sha256:cac08beec0a2d3554112aae593c63dfadda4e9192793351cf07f39c7f6706df4","layer_digest":"sha256:f8712d5eab7c627741d2b229c520156859e764641205d07a78a598a72a147c13","payload_sha256":"sha256:c5073b25dfb8f6b4136f62b9aa8e874bd9a38cbf8ce964a0a55cc86eee11a41f"},"operation_digest":"sha256:a33ee3eae67efc9098443c491a70df4711e70f4cc8a7da5691a99be39d1faf76"},{"seq":2,"op":"delete","id":"t","selector":{"architecture":["s390x"]},"artifact":{"repository":"oci://127.0.0.1:5532/ns/tree","manifest_digest":"sha256:b2b47fc759de49231fc9d9778cc42be4d6fbf5a12393bbb2fd62f75dcdd07066","layer_digest":"sha256:68d80fc35958ebbff8b82bbbbbf58dff8bc416b2a3e194ac0191499cf90bb14c","payload_sha256":"sha256:6d30cc3bd7b43b3ea26375e14353601f6d679c3b73d8434e76c83e5e8ac7ee99"},"operation_digest":"sha256:d9e8cb4347a5e43ace9b901a6ba8f068d8a306b31224a9a889e5c34e939101be"},{"seq":3,"op":"add","id":"t","selector":{"architecture":["s390x"]},"artifact":{"repository":"oci://127.0.0.1:5532/ns/tree","manifest_digest":"sha256:cac08beec0a2d3554112aae593c63dfadda4e9192793351cf07f39c7f6706df4","layer_digest":"sha256:f8712d5eab7c627741d2b229c520156859e764641205d07a78a598a72a147c13","payload_sha256":"sha256:c5073b25dfb8f6b4136f62b9aa8e874bd9a38cbf8ce964a0a55cc86eee11a41f"},"operation_digest":"sha256:a87247aa5b91f0df7c23d09c17b85e65d0de675323f02fa2a2edf7c7f4751164"}],"head":{"seq":3}}\ No newline at end of filediff --git a/testing/fuzz/corpus/upatch/load b/testing/fuzz/corpus/upatch/loadnew file mode 100644index 00000000..2469a39aBinary files /dev/null and b/testing/fuzz/corpus/upatch/load differdiff --git a/testing/fuzz/corpus/upatch/unload b/testing/fuzz/corpus/upatch/unloadnew file mode 100644index 00000000..cdc2ed2eBinary files /dev/null and b/testing/fuzz/corpus/upatch/unload differdiff --git a/testing/fuzz/fuzz-bpm-index.c b/testing/fuzz/fuzz-bpm-index.cnew file mode 100644index 00000000..08b9c59f--- /dev/null+++ b/testing/fuzz/fuzz-bpm-index.c@@ -0,0 +1,19 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * bpm_index_parse() on a repository index.+ */++#include "bpm_oci.h"+#include "bpm_package.h"+#include "fuzz.h"++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ static struct bpm_index_entry entries[BPM_MAX_ENTRIES];+ int n = 0;++ bpm_index_parse(data, size, entries, &n);+ return 0;+}diff --git a/testing/fuzz/fuzz-bpm-tar.c b/testing/fuzz/fuzz-bpm-tar.cnew file mode 100644index 00000000..a5ce90da--- /dev/null+++ b/testing/fuzz/fuzz-bpm-tar.c@@ -0,0 +1,28 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * bpm_pkg_read_member_in() reading the Beefile out of a gzip'd package+ * archive.+ */++#include "bpm_package.h"+#include "fuzz.h"+#include "malloc.h"++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ char path[64], dir[256];+ size_t len = 0;+ __u8 *body;+ int fd;++ fd = fuzz_file(data, size, path, sizeof(path));+ if (fd < 0)+ return 0;+ if (!bpm_pkg_read_member_in(path, "Beefile", NULL, dir, sizeof(dir),+ &body, &len, 1 << 20))+ xfree(body, len + 1);+ close(fd);+ return 0;+}diff --git a/testing/fuzz/fuzz-json.c b/testing/fuzz/fuzz-json.cnew file mode 100644index 00000000..a16da1ba--- /dev/null+++ b/testing/fuzz/fuzz-json.c@@ -0,0 +1,42 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * shirudo_json_parse() over a schema with every field type.+ */++#include "fuzz.h"+#include "json.h"+#include "macros.h"++static int on_elem(void *ctx)+{+ (*(int *)ctx)++;+ return 0;+}++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ char s[64], k[32], v[16];+ __s64 i = 0, n = 0;+ int b = 0, elems = 0;+ struct shirudo_json_array arr = { on_elem, &elems };+ struct shirudo_json_field obj[] = {+ { "k", SHIRUDO_JSON_T_STRING, k, sizeof(k), 0, NULL, 0 },+ { "n", SHIRUDO_JSON_T_INT, &n, 0, 0, NULL, 0 },+ };+ struct shirudo_json_field elem[] = {+ { "v", SHIRUDO_JSON_T_STRING, v, sizeof(v), 0, NULL, 0 },+ { "o", SHIRUDO_JSON_T_OBJECT, NULL, 0, 0, obj, ARRAY_SIZE(obj) },+ };+ struct shirudo_json_field root[] = {+ { "s", SHIRUDO_JSON_T_STRING, s, sizeof(s), 0, NULL, 0 },+ { "i", SHIRUDO_JSON_T_INT, &i, 0, 0, NULL, 0 },+ { "b", SHIRUDO_JSON_T_BOOL, &b, 0, 0, NULL, 0 },+ { "o", SHIRUDO_JSON_T_OBJECT, NULL, 0, 0, obj, ARRAY_SIZE(obj) },+ { "a", SHIRUDO_JSON_T_ARRAY, &arr, 0, 0, elem, ARRAY_SIZE(elem) },+ };++ shirudo_json_parse((const char *)data, size, root, ARRAY_SIZE(root));+ return 0;+}diff --git a/testing/fuzz/fuzz-oci-manifest.c b/testing/fuzz/fuzz-oci-manifest.cnew file mode 100644index 00000000..4fee31c2--- /dev/null+++ b/testing/fuzz/fuzz-oci-manifest.c@@ -0,0 +1,22 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * bpm_oci_parse_manifest() on what a registry returns, before anything+ * about it is verified.+ */++#include "bpm_oci.h"+#include "fuzz.h"+#include "macros.h"++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ static struct bpm_descriptor layers[16];+ char name[BPM_MAX_NAME];+ int n = 0;++ bpm_oci_parse_manifest(data, size, layers, ARRAY_SIZE(layers), &n,+ name, sizeof(name));+ return 0;+}diff --git a/testing/fuzz/fuzz-tree.c b/testing/fuzz/fuzz-tree.cnew file mode 100644index 00000000..a350cd3a--- /dev/null+++ b/testing/fuzz/fuzz-tree.c@@ -0,0 +1,27 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * shirudo_tree_parse() on an upatch tree publication, the canonical+ * digest of every operation it accepts and the publication emitted again.+ */++#include "bpm_tree.h"+#include "fuzz.h"+#include "malloc.h"++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ struct shirudo_tree_publication pub;+ char digest[72], *out;+ size_t len;++ if (shirudo_tree_parse((const char *)data, size, &pub))+ return 0;+ for (int i = 0; i < pub.n_operations; i++)+ shirudo_tree_operation_digest(&pub.operations[i], digest);+ if (!shirudo_tree_emit_publication(&pub, &out, &len))+ xfree(out, len);+ shirudo_tree_publication_free(&pub);+ return 0;+}diff --git a/testing/fuzz/fuzz-upatch.c b/testing/fuzz/fuzz-upatch.cnew file mode 100644index 00000000..f4148e65--- /dev/null+++ b/testing/fuzz/fuzz-upatch.c@@ -0,0 +1,32 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * shirudo_upatch_open() on a .upatch container, and its decoder table.+ */++#include "fuzz.h"+#include "upatch.h"++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ struct shirudo_upatch u;+ char path[64];+ int fd;++ fd = fuzz_file(data, size, path, sizeof(path));+ if (fd < 0)+ return 0;+ if (!shirudo_upatch_open(path, &u)) {+ shirudo_upatch_is_unload(&u);+ if (shirudo_upatch_has_decoders(&u)) {+ struct shirudo_upatch_decoder_view d;++ for (__u32 i = 0; !shirudo_upatch_decoder_view(&u, i, &d); i++)+ ;+ }+ shirudo_upatch_close(&u);+ }+ close(fd);+ return 0;+}diff --git a/testing/fuzz/fuzz.h b/testing/fuzz/fuzz.hnew file mode 100644index 00000000..313bfc35--- /dev/null+++ b/testing/fuzz/fuzz.h@@ -0,0 +1,45 @@+/* SPDX-License-Identifier: BSD-2-Clause */+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * What the libFuzzer targets for shirudo's parsers share.+ */++#ifndef SHIRUDO_FUZZ_H+#define SHIRUDO_FUZZ_H++#include <stddef.h>+#include <stdio.h>+#include <sys/mman.h>+#include <unistd.h>++#include <shirudo/misc.h>++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size);++/*+ * The input as a file for the parsers that read one by name: a memfd,+ * named through /proc/self/fd. -1, or the descriptor to close after.+ */+static inline int fuzz_file(const __u8 *data, size_t size, char *path,+ size_t cap)+{+ int fd = memfd_create("fuzz", MFD_CLOEXEC);+ size_t off = 0;++ if (fd < 0)+ return -1;+ while (off < size) {+ ssize_t n = write(fd, data + off, size - off);++ if (n <= 0) {+ close(fd);+ return -1;+ }+ off += (size_t)n;+ }+ snprintf(path, cap, "/proc/self/fd/%d", fd);+ return fd;+}++#endif /* SHIRUDO_FUZZ_H */diff --git a/testing/fuzz/run.sh b/testing/fuzz/run.shnew file mode 100755index 00000000..84f188e2--- /dev/null+++ b/testing/fuzz/run.sh@@ -0,0 +1,37 @@+#!/bin/sh+# 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 <seconds> [<target>...]++set -eu++cd "$(dirname "$0")"+seconds=${1:?usage: run.sh <seconds> [<target>...]}+shift+if [ $# -eq 0 ]; then+ set -- json oci-manifest bpm-index tree upatch bpm-tar+fi++work=$(mktemp -d)+trap 'rm -rf "$work"' EXIT++rc=0+for t in "$@"; do+ mkdir -p "$work/$t"+ if ./fuzz-"$t" -max_total_time="$seconds" -timeout=10 \+ -rss_limit_mb=2048 -artifact_prefix="$PWD/crash-$t-" \+ "$work/$t" "corpus/$t" >"$work/$t.log" 2>&1; then+ printf 'fuzz: %s: %s\n' "$t" "$(tail -n 1 "$work/$t.log")"+ else+ tail -n 40 "$work/$t.log" >&2+ printf 'fuzz: %s failed; the input is in testing/fuzz/crash-%s-*\n' \+ "$t" "$t" >&2+ rc=1+ fi+done+exit $rc