summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-11-12 21:30:25 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2021-11-14 12:13:28 -0800
commit6f84f3be1cdd3aadacc42007582116d1c2c0a3e4 (patch)
tree762b35b75c41b59cd0564fef4a9b511d3059a9e6 /src
parente1394a6408c86941417a700ff594e1bf26018c9e (diff)
downloadgrep-6f84f3be1cdd3aadacc42007582116d1c2c0a3e4.tar.gz
grep: Don’t limit jitstack_max to INT_MAX
* src/pcresearch.c (jit_exec): Remove arbitrary INT_MAX limit on JIT stack size.
Diffstat (limited to 'src')
-rw-r--r--src/pcresearch.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/pcresearch.c b/src/pcresearch.c
index daa0c424..bf966f80 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -59,10 +59,16 @@ jit_exec (struct pcre_comp *pc, char const *subject, PCRE2_SIZE search_bytes,
{
while (true)
{
+ /* STACK_GROWTH_RATE is taken from PCRE's src/pcre2_jit_compile.c.
+ Going over the jitstack_max limit could trigger an int
+ overflow bug within PCRE. */
+ int STACK_GROWTH_RATE = 8192;
+ size_t jitstack_max = SIZE_MAX - (STACK_GROWTH_RATE - 1);
+
int e = pcre2_match (pc->cre, (PCRE2_SPTR) subject, search_bytes,
search_offset, options, pc->data, pc->mcontext);
if (e == PCRE2_ERROR_JIT_STACKLIMIT
- && 0 < pc->jit_stack_size && pc->jit_stack_size <= INT_MAX / 2)
+ && 0 < pc->jit_stack_size && pc->jit_stack_size <= jitstack_max / 2)
{
PCRE2_SIZE old_size = pc->jit_stack_size;
PCRE2_SIZE new_size = pc->jit_stack_size = old_size * 2;