summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-08-05 21:32:13 +0000
committerKostya Serebryany <kcc@google.com>2015-08-05 21:32:13 +0000
commit1ce0035bf0cbbe3709473578a13e00b0731e8140 (patch)
treee48a35ddbf12d24e3175341308f3b4282aa7f422 /llvm/lib/Fuzzer
parent44f5d18587ebeb5c5a27c34ddd53c2cda25d4c9e (diff)
downloadbcm5719-llvm-1ce0035bf0cbbe3709473578a13e00b0731e8140.tar.gz
bcm5719-llvm-1ce0035bf0cbbe3709473578a13e00b0731e8140.zip
[libFuzzer] add a missing test file
llvm-svn: 244151
Diffstat (limited to 'llvm/lib/Fuzzer')
-rw-r--r--llvm/lib/Fuzzer/test/StrcmpTest.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/test/StrcmpTest.cpp b/llvm/lib/Fuzzer/test/StrcmpTest.cpp
new file mode 100644
index 00000000000..04264fa93fd
--- /dev/null
+++ b/llvm/lib/Fuzzer/test/StrcmpTest.cpp
@@ -0,0 +1,28 @@
+// 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" void 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);
+ }
+}
OpenPOWER on IntegriCloud