• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Break through a series of strcmp.
6 #include <cassert>
7 #include <cstdint>
8 #include <cstdio>
9 #include <cstdlib>
10 #include <cstring>
11 
Eq(const uint8_t * Data,size_t Size,const char * Str)12 bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
13   char Buff[1024];
14   size_t Len = strlen(Str);
15   if (Size < Len) return false;
16   if (Len >= sizeof(Buff)) return false;
17   memcpy(Buff, (const char*)Data, Len);
18   Buff[Len] = 0;
19   int res = strcmp(Buff, Str);
20   return res == 0;
21 }
22 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
24   if (Eq(Data, Size, "ABC") &&
25       Size >= 3 && Eq(Data + 3, Size - 3, "QWER") &&
26       Size >= 7 && Eq(Data + 7, Size - 7, "ZXCVN")) {
27     fprintf(stderr, "BINGO\n");
28     exit(1);
29   }
30   return 0;
31 }
32