summaryrefslogtreecommitdiff
path: root/fuzzing
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-10-12 14:48:09 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-10-12 14:48:09 +0000
commitc85f85a56b91ed92bf57600560873cda93e52860 (patch)
tree8a240fb7fd6c0e2f49b4e366d546aff7afc6de77 /fuzzing
parent7c31c8407b1b738efde95f08e8b809b8be6f11d0 (diff)
More fuzzing infastructre - regex
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@315582 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'fuzzing')
-rw-r--r--fuzzing/fuzzing.cpp58
-rw-r--r--fuzzing/fuzzing.h10
2 files changed, 65 insertions, 3 deletions
diff --git a/fuzzing/fuzzing.cpp b/fuzzing/fuzzing.cpp
index cc349cdee..d4d0e602c 100644
--- a/fuzzing/fuzzing.cpp
+++ b/fuzzing/fuzzing.cpp
@@ -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, size_t size)
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
diff --git a/fuzzing/fuzzing.h b/fuzzing/fuzzing.h
index b8116fbc1..6624955f8 100644
--- a/fuzzing/fuzzing.h
+++ b/fuzzing/fuzzing.h
@@ -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