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