aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_alg_strnstr.cpp
blob: 0c4286cd4dcead3ae18f478cf747da038ab6e176 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "ndpi_api.h"

#include "fuzzer/FuzzedDataProvider.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  FuzzedDataProvider fuzzed_data(data, size);
  u_int16_t len;
  u_char out[4096];

  /* No real memory allocations involved */

  len = fuzzed_data.ConsumeIntegral<u_int16_t>();
  std::string haystack = fuzzed_data.ConsumeRandomLengthString();
  std::string needle = fuzzed_data.ConsumeRandomLengthString();

  ndpi_strnstr(haystack.c_str(), needle.c_str(), len);

  ndpi_str_endswith(haystack.c_str(), needle.c_str());

  ndpi_str_to_utf8((u_char *)haystack.c_str(), strlen(haystack.c_str()), out, sizeof(out));

  return 0;
}