| 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 |
|
| 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 |
|
| 30 |
if (x > 1234567890 && PrintOnce(__LINE__) && |
| 31 |
x < 1234567895 && PrintOnce(__LINE__) && |
| 32 |
a == 0x4242 && PrintOnce(__LINE__) && |
| 33 |
y >= 987654321 && PrintOnce(__LINE__) && |
| 34 |
y <= 987654325 && PrintOnce(__LINE__) && |
| 35 |
z < -10000 && PrintOnce(__LINE__) && |
| 36 |
z >= -10005 && PrintOnce(__LINE__) && |
| 37 |
z != -10003 && PrintOnce(__LINE__) && |
| 38 |
true) { |
| 39 |
fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n", |
| 40 |
Size, x, y, z, a); |
| 41 |
exit(1); |
| 42 |
} |
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
int AllLines[__LINE__ + 1]; // Must be the last line. |