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