summaryrefslogtreecommitdiff
path: root/src/pcresearch.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-09-09 15:07:01 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-09-09 16:00:59 -0700
commit669a52ea60220bad4f72b06f5d200dbe729ea500 (patch)
tree6ddf763ab87b7739dfa1e1a2b1bd2be18ac023a5 /src/pcresearch.c
parent68dddcfd25715d14d8052833d6d6a84d277953b7 (diff)
downloadgrep-669a52ea60220bad4f72b06f5d200dbe729ea500.tar.gz
grep: fix logic for growing PCRE JIT stack
* src/pcresearch.c (jit_exec) [PCRE_EXTRA_MATCH_LIMIT_RECURSION]: When growing the match_limit_recursion limit, do not use the old value if ! (flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION), as it is uninitialized in that case.
Diffstat (limited to 'src/pcresearch.c')
-rw-r--r--src/pcresearch.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/pcresearch.c b/src/pcresearch.c
index e2650832..a668c455 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -90,16 +90,18 @@ jit_exec (struct pcre_comp *pc, char const *subject, int search_bytes,
#if PCRE_EXTRA_MATCH_LIMIT_RECURSION
if (e == PCRE_ERROR_RECURSIONLIMIT
- && (PCRE_STUDY_EXTRA_NEEDED || pc->extra)
- && pc->extra->match_limit_recursion <= ULONG_MAX / 2)
+ && (PCRE_STUDY_EXTRA_NEEDED || pc->extra))
{
- pc->extra->match_limit_recursion *= 2;
- if (pc->extra->match_limit_recursion == 0)
+ unsigned long lim
+ = (pc->extra->flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION
+ ? pc->extra->match_limit_recursion
+ : 0);
+ if (lim <= ULONG_MAX / 2)
{
- pc->extra->match_limit_recursion = (1 << 24) - 1;
+ pc->extra->match_limit_recursion = lim ? 2 * lim : (1 << 24) - 1;
pc->extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION;
+ continue;
}
- continue;
}
#endif