aboutsummaryrefslogtreecommitdiff
path: root/lib/Fuzzer/test/SimpleCmpTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Fuzzer/test/SimpleCmpTest.cpp')
-rw-r--r--lib/Fuzzer/test/SimpleCmpTest.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/Fuzzer/test/SimpleCmpTest.cpp b/lib/Fuzzer/test/SimpleCmpTest.cpp
new file mode 100644
index 000000000000..8568c737efb1
--- /dev/null
+++ b/lib/Fuzzer/test/SimpleCmpTest.cpp
@@ -0,0 +1,31 @@
+// Simple test for a fuzzer. The fuzzer must find several narrow ranges.
+#include <cstdint>
+#include <cstdlib>
+#include <cstring>
+#include <cstdio>
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Size < 14) return 0;
+ uint64_t x = 0;
+ int64_t y = 0;
+ int z = 0;
+ unsigned short a = 0;
+ memcpy(&x, Data, 8);
+ memcpy(&y, Data + Size - 8, 8);
+ memcpy(&z, Data + Size / 2, sizeof(z));
+ memcpy(&a, Data + Size / 2 + 4, sizeof(a));
+
+ if (x > 1234567890 &&
+ x < 1234567895 &&
+ y >= 987654321 &&
+ y <= 987654325 &&
+ z < -10000 &&
+ z >= -10005 &&
+ z != -10003 &&
+ a == 4242) {
+ fprintf(stderr, "BINGO; Found the target: size %zd (%zd, %zd, %d, %d), exiting.\n",
+ Size, x, y, z, a);
+ exit(1);
+ }
+ return 0;
+}