fuzz: when running as unit tests, allow -v and [corpus...] args.
What changed, and why it matters
This commit only changes the fuzz testing helper code used by developers. It lets developers pass a -v flag and pick specific test corpus files when running fuzz targets as ordinary unit tests. There is no change to production wallet, networking, or consensus code, and nothing here affects real users or live funds.
No security action needed. Treat as a normal non-security developer tooling commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies tests/fuzz/libfuzz.c, which is compiled only when FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION is not defined. It adds a small option parser to recognize -v and optional explicit corpus file names, prints names when verbose, and replaces an assert(contents) with err(1, …) if a corpus file cannot be read. This is purely a developer-facing test harness quality-of-life improvement.
Changed components
tests/fuzz/libfuzz.cInspect captured patch +19 / −2
diff --git a/tests/fuzz/libfuzz.c b/tests/fuzz/libfuzz.c
index 00e4b84d..8f8dc43e 100644
--- a/tests/fuzz/libfuzz.c
+++ b/tests/fuzz/libfuzz.c
@@ -1,6 +1,7 @@
#include "config.h"
#include <assert.h>
+#include <ccan/err/err.h>
#include <ccan/isaac/isaac64.h>
#include <ccan/short_types/short_types.h>
#include <ccan/tal/grab_file/grab_file.h>
@@ -130,24 +131,40 @@ size_t cross_over(const u8 *in1, size_t in1_size, const u8 *in2,
/* In non-fuzzing builds, these become unit tests which just run the corpora:
* this is also good for attaching a debugger to! */
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+static size_t find_opt(char *argv[], const char *opt)
+{
+ for (size_t i = 1; argv[i]; i++) {
+ if (streq(argv[i], opt))
+ return i;
+ }
+ return 0;
+}
+
int main(int argc, char *argv[])
{
DIR *d;
struct dirent *di;
+ int verbose_flag;
common_setup(argv[0]);
assert(chdir("tests/fuzz/corpora") == 0);
assert(chdir(path_basename(tmpctx, argv[0])) == 0);
- /* FIXME: Support explicit path args? */
init(&argc, &argv);
+ verbose_flag = find_opt(argv, "-v");
d = opendir(".");
while ((di = readdir(d)) != NULL) {
u8 *contents;
if (streq(di->d_name, ".") || streq(di->d_name, ".."))
continue;
+ /* If you specify options other than -v, they're test names */
+ if (argv[verbose_flag + 1] && !find_opt(argv, di->d_name))
+ continue;
+ if (verbose_flag)
+ printf("%s\n", di->d_name);
contents = grab_file_raw(tmpctx, di->d_name);
- assert(contents);
+ if (!contents)
+ err(1, "Could not read %s", di->d_name);
run(contents, tal_bytelen(contents));
}
closedir(d);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.