• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 several narrow ranges.
5 #include <cstdint>
6 #include <cstdlib>
7 #include <cstring>
8 #include <cstdio>
9 
LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)10 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
11   if (Size < 14) return 0;
12   uint64_t x = 0;
13   int64_t  y = 0;
14   int z = 0;
15   unsigned short a = 0;
16   memcpy(&x, Data, 8);
17   memcpy(&y, Data + Size - 8, 8);
18   memcpy(&z, Data + Size / 2, sizeof(z));
19   memcpy(&a, Data + Size / 2 + 4, sizeof(a));
20 
21   if (x > 1234567890 &&
22       x < 1234567895 &&
23       y >= 987654321 &&
24       y <= 987654325 &&
25       z < -10000 &&
26       z >= -10005 &&
27       z != -10003 &&
28       a == 4242) {
29     fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n",
30             Size, x, y, z, a);
31     exit(1);
32   }
33   return 0;
34 }
35