LLVM  4.0.0
StrncmpTest.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 // Simple test for a fuzzer. The fuzzer must find a particular string.
5 #include <cstring>
6 #include <cstdint>
7 #include <cstdio>
8 #include <cstdlib>
9 
10 static volatile int sink;
11 
12 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
13  // TODO: check other sizes.
14  char *S = (char*)Data;
15  if (Size >= 8 && strncmp(S, "123", 8))
16  sink = 1;
17  if (Size >= 8 && strncmp(S, "01234567", 8) == 0) {
18  if (Size >= 12 && strncmp(S + 8, "ABCD", 4) == 0) {
19  if (Size >= 14 && strncmp(S + 12, "XY", 2) == 0) {
20  if (Size >= 17 && strncmp(S + 14, "KLM", 3) == 0) {
21  fprintf(stderr, "BINGO\n");
22  exit(1);
23  }
24  }
25  }
26  }
27  return 0;
28 }
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition: StrncmpTest.cpp:12
static volatile int sink
Definition: StrncmpTest.cpp:10