[PATCH] D27729: [libFuzzer] Diff 20 - Update tests to use more general functions instead of posix specific.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 14:58:04 PST 2016


mpividori updated this revision to Diff 81313.
mpividori added a comment.

Update diff to remove `StrStr()`.


Repository:
  rL LLVM

https://reviews.llvm.org/D27729

Files:
  lib/Fuzzer/FuzzerUtil.h
  lib/Fuzzer/FuzzerUtilPosix.cpp
  lib/Fuzzer/FuzzerUtilWindows.cpp
  lib/Fuzzer/test/OutOfMemoryTest.cpp
  lib/Fuzzer/test/StrstrTest.cpp


Index: lib/Fuzzer/test/StrstrTest.cpp
===================================================================
--- lib/Fuzzer/test/StrstrTest.cpp
+++ lib/Fuzzer/test/StrstrTest.cpp
@@ -2,6 +2,7 @@
 // License. See LICENSE.TXT for details.
 
 // Test strstr and strcasestr hooks.
+#include "FuzzerUtil.h"
 #include <string>
 #include <string.h>
 #include <cstdint>
@@ -11,9 +12,9 @@
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
   if (Size < 4) return 0;
   std::string s(reinterpret_cast<const char*>(Data), Size);
-  if (strstr(s.c_str(), "FUZZ") &&
-      strcasestr(s.c_str(), "aBcD") &&
-      memmem(s.data(), s.size(), "kuku", 4)
+  if (fuzzer::StrStr(s.c_str(), "FUZZ") &&
+      fuzzer::StrCaseStr(s.c_str(), "aBcD") &&
+      fuzzer::SearchMemory(s.data(), s.size(), "kuku", 4)
       ) {
     fprintf(stderr, "BINGO\n");
     exit(1);
Index: lib/Fuzzer/test/OutOfMemoryTest.cpp
===================================================================
--- lib/Fuzzer/test/OutOfMemoryTest.cpp
+++ lib/Fuzzer/test/OutOfMemoryTest.cpp
@@ -2,6 +2,7 @@
 // License. See LICENSE.TXT for details.
 
 // Tests OOM handling.
+#include "FuzzerUtil.h"
 #include <assert.h>
 #include <cstdint>
 #include <cstdlib>
@@ -21,7 +22,7 @@
           char *p = new char[kSize];
           memset(p, 0, kSize);
           SinkPtr = p;
-          sleep(1);
+          fuzzer::SleepSeconds(1);
         }
       }
     }
Index: lib/Fuzzer/FuzzerUtilWindows.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtilWindows.cpp
+++ lib/Fuzzer/FuzzerUtilWindows.cpp
@@ -177,6 +177,19 @@
   return NULL;
 }
 
+static bool IgnoreCaseCmp(char a, char b) {
+  return ::tolower(a) == ::tolower(b);
+}
+
+const char *StrCaseStr(const char* Ref, const char* Patt) {
+  const char* RefEnd = Ref + ::strlen(Ref);
+  const char* PattEnd = Patt + ::strlen(Patt);
+  const char* It = std::search(Ref, RefEnd, Patt, PattEnd, IgnoreCaseCmp);
+  if (It == RefEnd)
+    return NULL;
+  return It;
+}
+
 } // namespace fuzzer
 
 #endif // LIBFUZZER_WINDOWS
Index: lib/Fuzzer/FuzzerUtilPosix.cpp
===================================================================
--- lib/Fuzzer/FuzzerUtilPosix.cpp
+++ lib/Fuzzer/FuzzerUtilPosix.cpp
@@ -112,6 +112,10 @@
   return memmem(Data, DataLen, Patt, PattLen);
 }
 
+const char *StrCaseStr(const char* Ref, const char* Patt) {
+  return strcasestr(Ref, Patt);
+}
+
 }  // namespace fuzzer
 
 #endif // LIBFUZZER_POSIX
Index: lib/Fuzzer/FuzzerUtil.h
===================================================================
--- lib/Fuzzer/FuzzerUtil.h
+++ lib/Fuzzer/FuzzerUtil.h
@@ -59,6 +59,8 @@
 const void *SearchMemory(const void *haystack, size_t haystacklen,
                          const void *needle, size_t needlelen);
 
+const char *StrCaseStr(const char* Ref, const char* Patt);
+
 std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
                               const char *X1, const char *X2);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27729.81313.patch
Type: text/x-patch
Size: 2990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161213/fb91fd96/attachment.bin>


More information about the llvm-commits mailing list