Skip to content
Snippets Groups Projects
Commit 504a0f88 authored by Sergey Bronnikov's avatar Sergey Bronnikov Committed by Igor Munkin
Browse files

test/fuzz: fix datetime_strptime fuzzing test

Function `datetime_strptime` decodes string with datetime according to
specified format, it accepts a datetime struct, buffer with datetime and
string with format in arguments. Fuzzing test used static string
"iso8601" as a format and it blocked fuzzing test to cover functions
used by datetime_strptime under the hood. Fuzz introspector shows that
code coveraged by a test is quite low.

Patch updates the test to make it more effective: buffer with datetime
and format string are generated using FDP (Fuzzing Data Provider).

Test file extension was changed to .cc, because FuzzingDataProvider is
used and we need building it by C++ compiler.

Function `tnt_strptime` uses assert, that triggered by fuzzing tests.
Therefore it was replaced with to if..then.

1. https://storage.googleapis.com/oss-fuzz-introspector/tarantool/

Fixes #8490

NO_CHANGELOG=fuzzing test
NO_DOC=fuzzing test
NO_TEST=fuzzing test

(cherry picked from commit a1bd6e0b)
parent 70b0fc1f
No related branches found
No related tags found
No related merge requests found
......@@ -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))
......
......@@ -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
)
......
#include <stdlib.h>
#include <string.h>
#include <fuzzer/FuzzedDataProvider.h>
#include <stddef.h>
#include "datetime.h"
#include "trivia/util.h"
void
extern "C" void
cord_on_yield(void) {}
int
extern "C" 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';
FuzzedDataProvider fdp(data, size);
auto buf = fdp.ConsumeRandomLengthString();
auto fmt = fdp.ConsumeRandomLengthString();
struct datetime date_expected;
datetime_strptime(&date_expected, buf, "iso8601");
free(buf);
datetime_strptime(&date_expected, buf.c_str(), fmt.c_str());
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment