1// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2// See https://llvm.org/LICENSE.txt for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5// Test strstr and strcasestr hooks.
6#include <cstdint>
7#include <cstdio>
8#include <cstdlib>
9#include <string.h>
10#include <string>
11
12// Windows does not have strcasestr and memmem, so we are not testing them.
13#ifdef _WIN32
14#define strcasestr strstr
15#define memmem(a, b, c, d) true
16#endif
17
18extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
19 if (Size < 4) return 0;
20 std::string s(reinterpret_cast<const char*>(Data), Size);
21 if (strstr(haystack: s.c_str(), needle: "FUZZ") &&
22 strcasestr(haystack: s.c_str(), needle: "aBcD") &&
23 memmem(haystack: s.data(), haystacklen: s.size(), needle: "kuku", needlelen: 4)
24 ) {
25 fprintf(stderr, format: "BINGO\n");
26 exit(status: 1);
27 }
28 return 0;
29}
30

source code of compiler-rt/test/fuzzer/StrstrTest.cpp