From 1ac753979a33bafc44e83ccf8f8180b87f56a67d Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Thu, 21 May 2020 10:23:28 +0100 Subject: [PATCH] Problem: z85_decode fuzzer does not run regression tests with corpora Solution: do it to avoid regressions --- tests/fuzzer_corpora/test_z85_decode_fuzzer.txt | 1 + tests/test_z85_decode_fuzzer.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/fuzzer_corpora/test_z85_decode_fuzzer.txt diff --git a/tests/fuzzer_corpora/test_z85_decode_fuzzer.txt b/tests/fuzzer_corpora/test_z85_decode_fuzzer.txt new file mode 100644 index 00000000..69f90d1a --- /dev/null +++ b/tests/fuzzer_corpora/test_z85_decode_fuzzer.txt @@ -0,0 +1 @@ +46555a5a2d54414746555a5ad6514147ec \ No newline at end of file diff --git a/tests/test_z85_decode_fuzzer.cpp b/tests/test_z85_decode_fuzzer.cpp index c0a65010..db37d3ba 100644 --- a/tests/test_z85_decode_fuzzer.cpp +++ b/tests/test_z85_decode_fuzzer.cpp @@ -60,10 +60,21 @@ extern "C" int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size) #ifndef ZMQ_USE_FUZZING_ENGINE void test_bind_null_fuzzer () { - uint8_t buffer[32] = {0}; + uint8_t **data; + size_t *len, num_cases = 0; + if (fuzzer_corpus_encode ("tests/fuzzer_corpora/test_z85_decode_fuzzer.txt", + &data, &len, &num_cases) + != 0) + exit (77); - TEST_ASSERT_SUCCESS_ERRNO ( - LLVMFuzzerTestOneInput (buffer, sizeof (buffer))); + while (num_cases-- > 0) { + TEST_ASSERT_SUCCESS_ERRNO ( + LLVMFuzzerTestOneInput (data[num_cases], len[num_cases])); + free (data[num_cases]); + } + + free (data); + free (len); } int main (int argc, char **argv)