diff --git a/src/lib/tzcode/strptime.c b/src/lib/tzcode/strptime.c index 4cc4351fc9ff8b0523bfe504aaacb9b370638ad2..6d1b7f24d1d5e0c36176a6d2e5e747eb24f4b976 100644 --- a/src/lib/tzcode/strptime.c +++ b/src/lib/tzcode/strptime.c @@ -262,7 +262,8 @@ tnt_strptime(const char *__restrict buf, const char *__restrict fmt, ; c = *ptr++; - assert(c == 'f'); + if (c != 'f') + return NULL; /* fallthru */ case 'f': if (!is_digit((u_char)*buf)) diff --git a/test/fuzz/CMakeLists.txt b/test/fuzz/CMakeLists.txt index a082b735af674c090fb6a35a5a0d8012ed144d2e..183b676e76ea7e3f444712e439d15bf10b9c9179 100644 --- a/test/fuzz/CMakeLists.txt +++ b/test/fuzz/CMakeLists.txt @@ -84,7 +84,7 @@ create_fuzz_test(PREFIX datetime_parse_full ) create_fuzz_test(PREFIX datetime_strptime - SOURCES datetime_strptime_fuzzer.c + SOURCES datetime_strptime_fuzzer.cc LIBRARIES core fuzzer_config ) diff --git a/test/fuzz/datetime_strptime_fuzzer.c b/test/fuzz/datetime_strptime_fuzzer.c deleted file mode 100644 index 0d00903e0e32604c777ef7996566463af5e0217f..0000000000000000000000000000000000000000 --- a/test/fuzz/datetime_strptime_fuzzer.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdlib.h> -#include <string.h> -#include "datetime.h" -#include "trivia/util.h" - -void -cord_on_yield(void) {} - -int -LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - char *buf = xcalloc(size + 1, sizeof(char)); - if (buf == NULL) - return 0; - memcpy(buf, data, size); - buf[size] = '\0'; - struct datetime date_expected; - datetime_strptime(&date_expected, buf, "iso8601"); - free(buf); - - return 0; -} diff --git a/test/fuzz/datetime_strptime_fuzzer.cc b/test/fuzz/datetime_strptime_fuzzer.cc new file mode 100644 index 0000000000000000000000000000000000000000..f644f38025d5f8a636184ae62693f93c3233af4c --- /dev/null +++ b/test/fuzz/datetime_strptime_fuzzer.cc @@ -0,0 +1,21 @@ +#include <fuzzer/FuzzedDataProvider.h> +#include <stddef.h> + +#include "datetime.h" + +extern "C" void +cord_on_yield(void) {} + +extern "C" int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + + auto buf = fdp.ConsumeRandomLengthString(); + auto fmt = fdp.ConsumeRandomLengthString(); + + struct datetime date_expected; + datetime_strptime(&date_expected, buf.c_str(), fmt.c_str()); + + return 0; +}