summaryrefslogtreecommitdiff
path: root/lib/Fuzzer/test/StrcmpTest.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:46:15 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:46:15 +0000
commitdd58ef019b700900793a1eb48b52123db01b654e (patch)
treefcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /lib/Fuzzer/test/StrcmpTest.cpp
parent2fe5752e3a7c345cdb59e869278d36af33c13fa4 (diff)
Notes
Diffstat (limited to 'lib/Fuzzer/test/StrcmpTest.cpp')
-rw-r--r--lib/Fuzzer/test/StrcmpTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/Fuzzer/test/StrcmpTest.cpp b/lib/Fuzzer/test/StrcmpTest.cpp
new file mode 100644
index 000000000000..835819ae2f45
--- /dev/null
+++ b/lib/Fuzzer/test/StrcmpTest.cpp
@@ -0,0 +1,29 @@
+// Break through a series of strcmp.
+#include <cstring>
+#include <cstdint>
+#include <cstdio>
+#include <cstdlib>
+#include <cassert>
+
+bool Eq(const uint8_t *Data, size_t Size, const char *Str) {
+ char Buff[1024];
+ size_t Len = strlen(Str);
+ if (Size < Len) return false;
+ if (Len >= sizeof(Buff)) return false;
+ memcpy(Buff, (char*)Data, Len);
+ Buff[Len] = 0;
+ int res = strcmp(Buff, Str);
+ return res == 0;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ if (Eq(Data, Size, "AAA") &&
+ Size >= 3 && Eq(Data + 3, Size - 3, "BBBB") &&
+ Size >= 7 && Eq(Data + 7, Size - 7, "CCCCCC") &&
+ Size >= 14 && Data[13] == 42
+ ) {
+ fprintf(stderr, "BINGO\n");
+ exit(1);
+ }
+ return 0;
+}