/src/ndpi/fuzz/fuzz_alg_strnstr.cpp
Line | Count | Source |
1 | | #include "ndpi_api.h" |
2 | | |
3 | | #include "fuzzer/FuzzedDataProvider.h" |
4 | | |
5 | 7.62k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
6 | 7.62k | FuzzedDataProvider fuzzed_data(data, size); |
7 | 7.62k | u_int16_t len; |
8 | 7.62k | u_char out[4096]; |
9 | | |
10 | | /* No real memory allocations involved */ |
11 | | |
12 | 7.62k | len = fuzzed_data.ConsumeIntegral<u_int16_t>(); |
13 | 7.62k | std::string haystack = fuzzed_data.ConsumeRandomLengthString(); |
14 | 7.62k | std::string needle = fuzzed_data.ConsumeRandomLengthString(); |
15 | | |
16 | 7.62k | ndpi_strnstr(haystack.c_str(), needle.c_str(), len); |
17 | | |
18 | 7.62k | ndpi_str_endswith(haystack.c_str(), needle.c_str()); |
19 | | |
20 | 7.62k | ndpi_str_to_utf8((u_char *)haystack.c_str(), strlen(haystack.c_str()), out, sizeof(out)); |
21 | | |
22 | 7.62k | return 0; |
23 | 7.62k | } |