[libcxx] r315582 - More fuzzing infastructre - regex
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 12 07:48:09 PDT 2017
Author: marshall
Date: Thu Oct 12 07:48:09 2017
New Revision: 315582
URL: http://llvm.org/viewvc/llvm-project?rev=315582&view=rev
Log:
More fuzzing infastructre - regex
Added:
libcxx/trunk/test/libcxx/fuzzing/regex_ECMAScript.cpp
libcxx/trunk/test/libcxx/fuzzing/regex_POSIX.cpp
libcxx/trunk/test/libcxx/fuzzing/regex_awk.cpp
libcxx/trunk/test/libcxx/fuzzing/regex_egrep.cpp
libcxx/trunk/test/libcxx/fuzzing/regex_extended.cpp
libcxx/trunk/test/libcxx/fuzzing/regex_grep.cpp
Modified:
libcxx/trunk/fuzzing/fuzzing.cpp
libcxx/trunk/fuzzing/fuzzing.h
Modified: libcxx/trunk/fuzzing/fuzzing.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzzing.cpp?rev=315582&r1=315581&r2=315582&view=diff
==============================================================================
--- libcxx/trunk/fuzzing/fuzzing.cpp (original)
+++ libcxx/trunk/fuzzing/fuzzing.cpp Thu Oct 12 07:48:09 2017
@@ -26,8 +26,7 @@
#include "fuzzing.h"
#include <vector>
#include <algorithm>
-
-#include <iostream>
+#include <regex>
// If we had C++14, we could use the four iterator version of is_permutation
@@ -219,4 +218,59 @@ int partial_sort (const uint8_t *data, s
return 0;
}
+
+// -- regex fuzzers
+
+static int regex_helper(const uint8_t *data, size_t size, std::regex::flag_type flag)
+{
+ if (size > 0)
+ {
+ try
+ {
+ std::string s((const char *)data, size);
+ std::regex re(s, flag);
+ return std::regex_match(s, re) ? 1 : 0;
+ }
+ catch (std::regex_error &ex) {}
+ }
+ return 0;
+}
+
+
+int regex_ECMAScript (const uint8_t *data, size_t size)
+{
+ (void) regex_helper(data, size, std::regex_constants::ECMAScript);
+ return 0;
+}
+
+int regex_POSIX (const uint8_t *data, size_t size)
+{
+ (void) regex_helper(data, size, std::regex_constants::basic);
+ return 0;
+}
+
+int regex_extended (const uint8_t *data, size_t size)
+{
+ (void) regex_helper(data, size, std::regex_constants::extended);
+ return 0;
+}
+
+int regex_awk (const uint8_t *data, size_t size)
+{
+ (void) regex_helper(data, size, std::regex_constants::awk);
+ return 0;
+}
+
+int regex_grep (const uint8_t *data, size_t size)
+{
+ (void) regex_helper(data, size, std::regex_constants::grep);
+ return 0;
+}
+
+int regex_egrep (const uint8_t *data, size_t size)
+{
+ (void) regex_helper(data, size, std::regex_constants::egrep);
+ return 0;
+}
+
} // namespace fuzzing
Modified: libcxx/trunk/fuzzing/fuzzing.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzzing.h?rev=315582&r1=315581&r2=315582&view=diff
==============================================================================
--- libcxx/trunk/fuzzing/fuzzing.h (original)
+++ libcxx/trunk/fuzzing/fuzzing.h Thu Oct 12 07:48:09 2017
@@ -27,7 +27,15 @@ namespace fuzzing {
int nth_element (const uint8_t *data, size_t size);
int partial_sort (const uint8_t *data, size_t size);
-
+
+// Various flavors of regex
+ int regex_ECMAScript (const uint8_t *data, size_t size);
+ int regex_POSIX (const uint8_t *data, size_t size);
+ int regex_extended (const uint8_t *data, size_t size);
+ int regex_awk (const uint8_t *data, size_t size);
+ int regex_grep (const uint8_t *data, size_t size);
+ int regex_egrep (const uint8_t *data, size_t size);
+
} // namespace fuzzing
#endif // _LIBCPP_FUZZING
Added: libcxx/trunk/test/libcxx/fuzzing/regex_ECMAScript.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/fuzzing/regex_ECMAScript.cpp?rev=315582&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/fuzzing/regex_ECMAScript.cpp (added)
+++ libcxx/trunk/test/libcxx/fuzzing/regex_ECMAScript.cpp Thu Oct 12 07:48:09 2017
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===--------------------- regex_ECMAScript.cpp ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL
+
+#include "fuzzing.h"
+#include <cassert>
+#include <cstring> // for strlen
+
+const char * test_cases[] = {
+ "",
+ "s",
+ "b*c",
+ "ba?sf"
+ "lka*ea",
+ "adsf*kas;lnc441[0-9]1r34525234"
+ };
+
+const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]);
+
+int main ()
+{
+ for (size_t i = 0; i < k_num_tests; ++i)
+ {
+ const size_t size = std::strlen(test_cases[i]);
+ const uint8_t *data = (const uint8_t *) test_cases[i];
+ assert(0 == fuzzing::regex_ECMAScript(data, size));
+ }
+ return 0;
+}
Added: libcxx/trunk/test/libcxx/fuzzing/regex_POSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/fuzzing/regex_POSIX.cpp?rev=315582&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/fuzzing/regex_POSIX.cpp (added)
+++ libcxx/trunk/test/libcxx/fuzzing/regex_POSIX.cpp Thu Oct 12 07:48:09 2017
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===----------------------- regex_POSIX.cpp ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL
+
+#include "fuzzing.h"
+#include <cassert>
+#include <cstring> // for strlen
+
+const char * test_cases[] = {
+ "",
+ "s",
+ "b*c",
+ "ba?sf"
+ "lka*ea",
+ "adsf*kas;lnc441[0-9]1r34525234"
+ };
+
+const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]);
+
+int main ()
+{
+ for (size_t i = 0; i < k_num_tests; ++i)
+ {
+ const size_t size = std::strlen(test_cases[i]);
+ const uint8_t *data = (const uint8_t *) test_cases[i];
+ assert(0 == fuzzing::regex_POSIX(data, size));
+ }
+ return 0;
+}
Added: libcxx/trunk/test/libcxx/fuzzing/regex_awk.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/fuzzing/regex_awk.cpp?rev=315582&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/fuzzing/regex_awk.cpp (added)
+++ libcxx/trunk/test/libcxx/fuzzing/regex_awk.cpp Thu Oct 12 07:48:09 2017
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===--------------------- regex_ECMAScript.cpp ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL
+
+#include "fuzzing.h"
+#include <cassert>
+#include <cstring> // for strlen
+
+const char * test_cases[] = {
+ "",
+ "s",
+ "b*c",
+ "ba?sf"
+ "lka*ea",
+ "adsf*kas;lnc441[0-9]1r34525234"
+ };
+
+const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]);
+
+int main ()
+{
+ for (size_t i = 0; i < k_num_tests; ++i)
+ {
+ const size_t size = std::strlen(test_cases[i]);
+ const uint8_t *data = (const uint8_t *) test_cases[i];
+ assert(0 == fuzzing::regex_ECMAScript(data, size));
+ }
+ return 0;
+}
Added: libcxx/trunk/test/libcxx/fuzzing/regex_egrep.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/fuzzing/regex_egrep.cpp?rev=315582&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/fuzzing/regex_egrep.cpp (added)
+++ libcxx/trunk/test/libcxx/fuzzing/regex_egrep.cpp Thu Oct 12 07:48:09 2017
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===------------------------ regex_egrep.cpp -----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL
+
+#include "fuzzing.h"
+#include <cassert>
+#include <cstring> // for strlen
+
+const char * test_cases[] = {
+ "",
+ "s",
+ "b*c",
+ "ba?sf"
+ "lka*ea",
+ "adsf*kas;lnc441[0-9]1r34525234"
+ };
+
+const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]);
+
+int main ()
+{
+ for (size_t i = 0; i < k_num_tests; ++i)
+ {
+ const size_t size = std::strlen(test_cases[i]);
+ const uint8_t *data = (const uint8_t *) test_cases[i];
+ assert(0 == fuzzing::regex_egrep(data, size));
+ }
+ return 0;
+}
Added: libcxx/trunk/test/libcxx/fuzzing/regex_extended.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/fuzzing/regex_extended.cpp?rev=315582&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/fuzzing/regex_extended.cpp (added)
+++ libcxx/trunk/test/libcxx/fuzzing/regex_extended.cpp Thu Oct 12 07:48:09 2017
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===---------------------- regex_extended.cpp ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL
+
+#include "fuzzing.h"
+#include <cassert>
+#include <cstring> // for strlen
+
+const char * test_cases[] = {
+ "",
+ "s",
+ "b*c",
+ "ba?sf"
+ "lka*ea",
+ "adsf*kas;lnc441[0-9]1r34525234"
+ };
+
+const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]);
+
+int main ()
+{
+ for (size_t i = 0; i < k_num_tests; ++i)
+ {
+ const size_t size = std::strlen(test_cases[i]);
+ const uint8_t *data = (const uint8_t *) test_cases[i];
+ assert(0 == fuzzing::regex_extended(data, size));
+ }
+ return 0;
+}
Added: libcxx/trunk/test/libcxx/fuzzing/regex_grep.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/fuzzing/regex_grep.cpp?rev=315582&view=auto
==============================================================================
--- libcxx/trunk/test/libcxx/fuzzing/regex_grep.cpp (added)
+++ libcxx/trunk/test/libcxx/fuzzing/regex_grep.cpp Thu Oct 12 07:48:09 2017
@@ -0,0 +1,37 @@
+// -*- C++ -*-
+//===------------------------ regex_grep.cpp ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// XFAIL
+
+#include "fuzzing.h"
+#include <cassert>
+#include <cstring> // for strlen
+
+const char * test_cases[] = {
+ "",
+ "s",
+ "b*c",
+ "ba?sf"
+ "lka*ea",
+ "adsf*kas;lnc441[0-9]1r34525234"
+ };
+
+const size_t k_num_tests = sizeof(test_cases)/sizeof(test_cases[0]);
+
+int main ()
+{
+ for (size_t i = 0; i < k_num_tests; ++i)
+ {
+ const size_t size = std::strlen(test_cases[i]);
+ const uint8_t *data = (const uint8_t *) test_cases[i];
+ assert(0 == fuzzing::regex_grep(data, size));
+ }
+ return 0;
+}
More information about the cfe-commits
mailing list