Commit e9d8ca5ea2 for bind
commit e9d8ca5ea2f392f0fa0a677132d51ff80e9596ef
Author: Michal Nowak <mnowak@isc.org>
Date: Thu Jun 4 13:56:52 2026 +0000
Fail corpus replay when no inputs are tested
The mock main used for corpus replay silently returned success when
the corpus directory was missing or empty, so a naming mismatch could
turn "meson test --suite fuzz" into a no-op without anyone noticing.
Exit non-zero when no input was fed to the target, and also when an
input could not be read, so that a partially replayed corpus does not
pass either.
Assisted-by: Claude:claude-opus-4-8
Assisted-by: Codex:gpt-6
diff --git a/fuzz/main.c b/fuzz/main.c
index 9191f39f6f..bac824f7dc 100644
--- a/fuzz/main.c
+++ b/fuzz/main.c
@@ -31,9 +31,10 @@
#include <dirent.h>
-static void
+static int
test_one_file(const char *filename) {
int fd;
+ int result = 1;
struct stat st;
char *data;
ssize_t n;
@@ -41,7 +42,7 @@ test_one_file(const char *filename) {
if ((fd = open(filename, O_RDONLY)) == -1) {
fprintf(stderr, "Failed to open %s: %s\n", filename,
strerror(errno));
- return;
+ return 1;
}
if (fstat(fd, &st) != 0) {
@@ -50,13 +51,23 @@ test_one_file(const char *filename) {
goto closefd;
}
- data = malloc(st.st_size);
+ if (!S_ISREG(st.st_mode)) {
+ fprintf(stderr, "Not a corpus file: %s\n", filename);
+ goto closefd;
+ }
+
+ data = malloc(st.st_size != 0 ? st.st_size : 1);
+ if (data == NULL) {
+ fprintf(stderr, "Failed to allocate input for %s\n", filename);
+ goto closefd;
+ }
n = read(fd, data, st.st_size);
if (n == st.st_size) {
printf("testing %zd bytes from %s\n", n, filename);
fflush(stdout);
LLVMFuzzerTestOneInput((const uint8_t *)data, n);
fflush(stderr);
+ result = 0;
} else {
if (n < 0) {
fprintf(stderr,
@@ -71,16 +82,21 @@ test_one_file(const char *filename) {
free(data);
closefd:
close(fd);
+ return result;
}
-static void
+static int
test_all_from(const char *dirname) {
DIR *dirp;
struct dirent *dp;
+ size_t tested = 0;
+ int result = 0;
dirp = opendir(dirname);
if (dirp == NULL) {
- return;
+ fprintf(stderr, "Failed to open corpus %s: %s\n", dirname,
+ strerror(errno));
+ return 1;
}
while ((dp = readdir(dirp)) != NULL) {
@@ -91,10 +107,19 @@ test_all_from(const char *dirname) {
}
snprintf(filename, sizeof(filename), "%s/%s", dirname,
dp->d_name);
- test_one_file(filename);
+ if (test_one_file(filename) != 0) {
+ result = 1;
+ } else {
+ tested++;
+ }
}
closedir(dirp);
+ if (tested == 0) {
+ fprintf(stderr, "No corpus inputs tested in %s\n", dirname);
+ return 1;
+ }
+ return result;
}
int
@@ -118,16 +143,17 @@ main(int argc, char **argv) {
if (argv[1] != NULL) {
while (argv[1] != NULL) {
- test_one_file(argv[1]);
+ if (test_one_file(argv[1]) != 0) {
+ ret = 1;
+ }
argv++;
argc--;
}
POST(argc);
- return 0;
+ return ret;
}
target = (target != NULL) ? target + 1 : argv[0];
- /* The binaries are named fuzz_<name>, the corpora are <name>.in. */
tail = isc_string_stripprefix(target, "fuzz_");
if (tail != NULL) {
target = tail;
@@ -135,9 +161,7 @@ main(int argc, char **argv) {
snprintf(corpusdir, sizeof(corpusdir), FUZZDIR "/%s.in", target);
- test_all_from(corpusdir);
-
- return 0;
+ return test_all_from(corpusdir);
}
#elif defined(ENABLE_AFL) && __AFL_COMPILER