summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-11-09 10:11:42 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2021-11-09 10:12:23 -0800
commitb3a85a1a8a816f4f6f9c01399c16efe92a86ca06 (patch)
treeeeb0f2c52009e1d6368314c54c0c941cadae2030 /src
parentc562691787709e5ebfec9f298f8d702efe8291b7 (diff)
downloadgrep-b3a85a1a8a816f4f6f9c01399c16efe92a86ca06.tar.gz
grep: work around PCRE bug
Problem reported by Carlo Marcelo Arenas Belón (Bug#51710). * src/pcresearch.c (jit_exec): Don’t attempt to grow the JIT stack over INT_MAX - 8 * 1024.
Diffstat (limited to 'src')
-rw-r--r--src/pcresearch.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/pcresearch.c b/src/pcresearch.c
index 3bdaee90..09f92c85 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -72,8 +72,11 @@ jit_exec (struct pcre_comp *pc, char const *subject, int search_bytes,
search_offset, options, sub, NSUB);
#if PCRE_STUDY_JIT_COMPILE
+ /* Going over this would trigger an int overflow bug within PCRE. */
+ int jitstack_max = INT_MAX - 8 * 1024;
+
if (e == PCRE_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)
{
int old_size = pc->jit_stack_size;
int new_size = pc->jit_stack_size = old_size * 2;