diff options
-rw-r--r-- | fuzz/Makefile.am | 4 | ||||
-rw-r--r-- | fuzz/main.c | 45 |
2 files changed, 38 insertions, 11 deletions
diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am index 9093034aca..3483f0cc81 100644 --- a/fuzz/Makefile.am +++ b/fuzz/Makefile.am @@ -57,10 +57,12 @@ gnutls_set_trust_file_fuzzer_LDADD = $(LDADD) $(LIBDL) #EXTRA_DIST = $(wildcard *.options) $(wildcard *.dict) \ # $(wildcard *.in) $(wildcard *.repro) +# We don't include the fuzz corpora into the tarball. +# Testing the corpora during dev cycles and in the CI is enough. dist-hook: find . -name '*.options' -exec cp -v '{}' $(distdir) ';' find . -name '*.dict' -exec cp -v '{}' $(distdir) ';' - find . -name '*.in' -exec cp -vr '{}' $(distdir) ';' +# find . -name '*.in' -exec cp -vr '{}' $(distdir) ';' find . -name '*.repro' -exec cp -vr '{}' $(distdir) ';' TESTS = $(FUZZERS) diff --git a/fuzz/main.c b/fuzz/main.c index 5ef0b99e1c..cdeba17238 100644 --- a/fuzz/main.c +++ b/fuzz/main.c @@ -37,7 +37,13 @@ #include <dirent.h> -static void test_all_from(const char *dirname) +#ifdef _WIN32 +# define SLASH '\\' +#else +# define SLASH '/' +#endif + +static int test_all_from(const char *dirname) { DIR *dirp; struct dirent *dp; @@ -76,27 +82,46 @@ static void test_all_from(const char *dirname) close(fd); } closedir(dirp); + return 0; } + + return 1; } int main(int argc, char **argv) { - const char *target = strrchr(argv[0], '/'); - target = target ? target + 1 : argv[0]; + const char *target; + size_t target_len; - char corporadir[sizeof(SRCDIR) + 1 + strlen(target) + 8]; + if ((target = strrchr(argv[0], SLASH))) + target = strrchr(target, '/'); + else + target = strrchr(argv[0], '/'); + target = target ? target + 1 : argv[0]; - if (strncmp(target, "lt-", 3) == 0) { + if (strncmp(target, "lt-", 3) == 0) target += 3; - } - snprintf(corporadir, sizeof(corporadir), SRCDIR "/%s.in", target); + target_len = strlen(target); + +#ifdef _WIN32 + target_len -= 4; // ignore .exe +#endif - test_all_from(corporadir); + { + int rc; + char corporadir[sizeof(SRCDIR) + 1 + target_len + 8]; + snprintf(corporadir, sizeof(corporadir), SRCDIR "/%.*s.in", (int) target_len, target); - snprintf(corporadir, sizeof(corporadir), SRCDIR "/%s.repro", target); + rc = test_all_from(corporadir); + if (rc) + fprintf(stderr, "Failed to find %s\n", corporadir); - test_all_from(corporadir); + snprintf(corporadir, sizeof(corporadir), SRCDIR "/%.*s.repro", (int) target_len, target); + + if (test_all_from(corporadir) && rc) + return 77; + } return 0; } |