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 <cstdio>
7 #include <cstdlib>
8 #include <cstring>
9 
10 extern int AllLines[];
11 
12 bool PrintOnce(int Line) {
13   if (!AllLines[Line])
14     fprintf(stderr, "Seen line %d\n", Line);
15   AllLines[Line] = 1;
16   return true;
17 }
18 
19 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
20   if (Size != 22) return 0;
21   uint64_t x = 0;
22   int64_t  y = 0;
23   int32_t z = 0;
24   uint16_t a = 0;
25   memcpy(&x, Data, 8);  // 8
26   memcpy(&y, Data + 8, 8);  // 16
27   memcpy(&z, Data + 16, sizeof(z));  // 20
28   memcpy(&a, Data + 20, sizeof(a));  // 22
29   const bool k32bit = sizeof(void*) == 4;
30 
31   if ((k32bit || x > 1234567890) && PrintOnce(__LINE__) &&
32       (k32bit || x < 1234567895) && PrintOnce(__LINE__) &&
33       a == 0x4242 && PrintOnce(__LINE__) &&
34       (k32bit || y >= 987654321) && PrintOnce(__LINE__) &&
35       (k32bit || y <= 987654325) && PrintOnce(__LINE__) &&
36       z < -10000 && PrintOnce(__LINE__) &&
37       z >= -10005 && PrintOnce(__LINE__) &&
38       z != -10003 && PrintOnce(__LINE__) &&
39       true) {
40     fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n",
41             Size, x, y, z, a);
42     exit(1);
43   }
44   return 0;
45 }
46 
47 int AllLines[__LINE__ + 1];  // Must be the last line.
48