Skip to content

Commit bdeec5f

Browse files
k-takatanobu
authored andcommitted
[k-takata/Onigmo] Fix stack overflow with X+++++++++++++++++++…
Imported the fix from: kkos/oniguruma@4097828 k-takata/Onigmo@786b4849c1
1 parent 2f84924 commit bdeec5f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

regparse.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6313,11 +6313,14 @@ parse_exp(Node** np, OnigToken* tok, int term,
63136313
int r, len, group = 0;
63146314
Node* qn;
63156315
Node** targetp;
6316+
unsigned int parse_depth;
63166317

63176318
*np = NULL;
63186319
if (tok->type == (enum TokenSyms )term)
63196320
goto end_of_token;
63206321

6322+
parse_depth = env->parse_depth;
6323+
63216324
switch (tok->type) {
63226325
case TK_ALT:
63236326
case TK_EOT:
@@ -6628,6 +6631,10 @@ parse_exp(Node** np, OnigToken* tok, int term,
66286631
if (is_invalid_quantifier_target(*targetp))
66296632
return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;
66306633

6634+
parse_depth++;
6635+
if (parse_depth > ParseDepthLimit)
6636+
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;
6637+
66316638
qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper,
66326639
(r == TK_INTERVAL ? 1 : 0));
66336640
CHECK_NULL_RETURN_MEMERR(qn);

0 commit comments

Comments
 (0)