Skip to content

Commit c80cd8a

Browse files
committed
jit: avoid wraparound in stack size
pcre2_jit_stack_create() allows the user to indicate how big of a stack size, JIT should be able to allocate and use, using a size_t variable that should be able to hold bigger values than reasonable. Internally, the value is rounded to the next 8K, but if the value is unreasonable large, would overflow. Avoid the overflowing by checking and failing the value early, and while at it make the check clearer and document the failure mode. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]>
1 parent 4689060 commit c80cd8a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

doc/pcre2_jit_stack_create.3

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ allocation. The result can be passed to the JIT run-time code by calling
2222
\fBpcre2_jit_stack_assign()\fP to associate the stack with a compiled pattern,
2323
which can then be processed by \fBpcre2_match()\fP or \fBpcre2_jit_match()\fP.
2424
A maximum stack size of 512KiB to 1MiB should be more than enough for any
25-
pattern. For more details, see the
25+
pattern. If the stack couldn't be allocated or the values passed were not
26+
reasonable, NULL will be returned. For more details, see the
2627
.\" HREF
2728
\fBpcre2jit\fP
2829
.\"

src/pcre2_jit_misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ return NULL;
135135

136136
pcre2_jit_stack *jit_stack;
137137

138-
if (startsize < 1 || maxsize < 1)
138+
if (startsize == 0 || maxsize == 0 || maxsize > PCRE2_SIZE_MAX - STACK_GROWTH_RATE)
139139
return NULL;
140140
if (startsize > maxsize)
141141
startsize = maxsize;

0 commit comments

Comments
 (0)