1c5f01b2fSopenharmony_ci// This file is distributed under the University of Illinois Open Source
2c5f01b2fSopenharmony_ci// License. See LICENSE.TXT for details.
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ci// Test strstr and strcasestr hooks.
5c5f01b2fSopenharmony_ci#include <string>
6c5f01b2fSopenharmony_ci#include <string.h>
7c5f01b2fSopenharmony_ci#include <cstdint>
8c5f01b2fSopenharmony_ci#include <cstdio>
9c5f01b2fSopenharmony_ci#include <cstdlib>
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci// Windows does not have strcasestr and memmem, so we are not testing them.
12c5f01b2fSopenharmony_ci#ifdef _WIN32
13c5f01b2fSopenharmony_ci#define strcasestr strstr
14c5f01b2fSopenharmony_ci#define memmem(a, b, c, d) true
15c5f01b2fSopenharmony_ci#endif
16c5f01b2fSopenharmony_ci
17c5f01b2fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
18c5f01b2fSopenharmony_ci  if (Size < 4) return 0;
19c5f01b2fSopenharmony_ci  std::string s(reinterpret_cast<const char*>(Data), Size);
20c5f01b2fSopenharmony_ci  if (strstr(s.c_str(), "FUZZ") &&
21c5f01b2fSopenharmony_ci      strcasestr(s.c_str(), "aBcD") &&
22c5f01b2fSopenharmony_ci      memmem(s.data(), s.size(), "kuku", 4)
23c5f01b2fSopenharmony_ci      ) {
24c5f01b2fSopenharmony_ci    fprintf(stderr, "BINGO\n");
25c5f01b2fSopenharmony_ci    exit(1);
26c5f01b2fSopenharmony_ci  }
27c5f01b2fSopenharmony_ci  return 0;
28c5f01b2fSopenharmony_ci}
29