LLVM  4.0.0
StrcmpTest.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 // Break through a series of strcmp.
5 #include <cstring>
6 #include <cstdint>
7 #include <cstdio>
8 #include <cstdlib>
9 #include <cassert>
10 
11 bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
12  char Buff[1024];
13  size_t Len = strlen(Str);
14  if (Size < Len) return false;
15  if (Len >= sizeof(Buff)) return false;
16  memcpy(Buff, (char*)Data, Len);
17  Buff[Len] = 0;
18  int res = strcmp(Buff, Str);
19  return res == 0;
20 }
21 
22 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
23  if (Eq(Data, Size, "ABC") &&
24  Size >= 3 && Eq(Data + 3, Size - 3, "QWER") &&
25  Size >= 7 && Eq(Data + 7, Size - 7, "ZXCVN") &&
26  Size >= 14 && Data[13] == 42
27  ) {
28  fprintf(stderr, "BINGO\n");
29  exit(1);
30  }
31  return 0;
32 }
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition: StrcmpTest.cpp:22
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with strcmp
bool Eq(const uint8_t *Data, size_t Size, const char *Str)
Definition: StrcmpTest.cpp:11