summaryrefslogtreecommitdiff
path: root/src/pcre2_fuzzsupport.c
diff options
context:
space:
mode:
authorph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2016-12-20 17:10:30 +0000
committerph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>2016-12-20 17:10:30 +0000
commit960b1a58162c2199bbefcc20e165be5c1e020bf1 (patch)
tree6a68f16697c8aa3c332469a4fe67ee07dc0c563a /src/pcre2_fuzzsupport.c
parent6716a7e1bc1c89402dc6ed6f801bd06cbb69841d (diff)
downloadpcre2-960b1a58162c2199bbefcc20e165be5c1e020bf1.tar.gz
Limit the fuzzing function with match limit = recursion limit = 100.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@621 6239d852-aaf2-0410-a92c-79f79f948069
Diffstat (limited to 'src/pcre2_fuzzsupport.c')
-rw-r--r--src/pcre2_fuzzsupport.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/pcre2_fuzzsupport.c b/src/pcre2_fuzzsupport.c
index 28f428a..e228a83 100644
--- a/src/pcre2_fuzzsupport.c
+++ b/src/pcre2_fuzzsupport.c
@@ -44,6 +44,7 @@ int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
uint32_t compile_options;
uint32_t match_options;
pcre2_match_data *match_data = NULL;
+pcre2_match_context *match_context = NULL;
int r1, r2;
int i;
@@ -120,7 +121,9 @@ for (i = 0; i < 2; i++)
int j;
uint32_t save_match_options = match_options;
- /* Create a match data block only when we first need it. */
+ /* Create match data and context blocks only when we first need them. Set
+ low match and recursion limits to avoid wasting too much searching large
+ pattern trees. Almost all matches are going to fail. */
if (match_data == NULL)
{
@@ -134,6 +137,20 @@ for (i = 0; i < 2; i++)
}
}
+ if (match_context == NULL)
+ {
+ match_context = pcre2_match_context_create(NULL);
+ if (match_context == NULL)
+ {
+#ifdef STANDALONE
+ printf("** Failed to create match context block\n");
+#endif
+ return 0;
+ }
+ pcre2_set_match_limit(match_context, 100);
+ pcre2_set_recursion_limit(match_context, 100);
+ }
+
/* Match twice, with and without options */
for (j = 0; j < 2; j++)
@@ -152,7 +169,7 @@ for (i = 0; i < 2; i++)
#endif
errorcode = pcre2_match(code, (PCRE2_SPTR)data, (PCRE2_SIZE)size, 0,
- match_options, match_data, NULL);
+ match_options, match_data, match_context);
#ifdef STANDALONE
if (errorcode >= 0) printf("Match returned %d\n", errorcode); else
@@ -187,6 +204,8 @@ for (i = 0; i < 2; i++)
}
if (match_data != NULL) pcre2_match_data_free(match_data);
+if (match_context != NULL) pcre2_match_context_free(match_context);
+
return 0;
}