[llvm] r244151 - [libFuzzer] add a missing test file

Kostya Serebryany kcc at google.com
Wed Aug 5 14:32:13 PDT 2015


Author: kcc
Date: Wed Aug  5 16:32:13 2015
New Revision: 244151

URL: http://llvm.org/viewvc/llvm-project?rev=244151&view=rev
Log:
[libFuzzer] add a missing test file

Added:
    llvm/trunk/lib/Fuzzer/test/StrcmpTest.cpp

Added: llvm/trunk/lib/Fuzzer/test/StrcmpTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/test/StrcmpTest.cpp?rev=244151&view=auto
==============================================================================
--- llvm/trunk/lib/Fuzzer/test/StrcmpTest.cpp (added)
+++ llvm/trunk/lib/Fuzzer/test/StrcmpTest.cpp Wed Aug  5 16:32:13 2015
@@ -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);
+  }
+}




More information about the llvm-commits mailing list