From fa5947d3e7e2c6f5010e39265d22c44b8e4b6793 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 5 May 2022 14:06:08 +0100 Subject: [PATCH 1/2] fuzzing: Add unit tests to check fuzzers Test the fuzzers with one arbitrary input each, to ensure that they work at a very basic level. This should catch regressions in each of the fuzzers without having to wait for them to be picked up by oss-fuzz. These tests can be run using `meson test --suite fuzzing`. Signed-off-by: Philip Withnall --- fuzzing/meson.build | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fuzzing/meson.build b/fuzzing/meson.build index 259c6d91d..d69381c63 100644 --- a/fuzzing/meson.build +++ b/fuzzing/meson.build @@ -38,4 +38,14 @@ foreach target_name : fuzz_targets c_args : extra_c_args, dependencies : deps, ) + + # If the FuzzingEngine isn’t available, build some unit tests to check that + # the fuzzing files do basically work. This doesn’t do any actual fuzzing though. + # Pass in the README as an arbitrary fuzzing input, just so we have something. + if not fuzzing_engine.found() + test(target_name, exe, + args : files('README.md'), + suite : 'fuzzing', + ) + endif endforeach From 70e7161bc5ac584b771a74632a12ff98c5747f8b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 5 May 2022 16:32:27 +0100 Subject: [PATCH 2/2] fuzzing: Only set the writer function once This should fix fuzzing builds since commit dfb3517d. Signed-off-by: Philip Withnall oss-fuzz#47108 --- fuzzing/fuzz.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fuzzing/fuzz.h b/fuzzing/fuzz.h index 4a879984c..5f999be0e 100644 --- a/fuzzing/fuzz.h +++ b/fuzzing/fuzz.h @@ -17,6 +17,12 @@ static void fuzz_set_logging_func (void) { #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - g_log_set_writer_func (empty_logging_func, NULL, NULL); + static gboolean writer_set = FALSE; + + if (!writer_set) + { + g_log_set_writer_func (empty_logging_func, NULL, NULL); + writer_set = TRUE; + } #endif }