Skip to content

Commit 4097828

Browse files
author
K.Kosako
committed
fix #147: Stack Exhaustion Problem caused by some parsing functions in regcomp.c making recursive calls to themselves.
1 parent 2b6b502 commit 4097828

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: src/regparse.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -6239,6 +6239,7 @@ parse_char_class(Node** np, PToken* tok, UChar** src, UChar* end, ScanEnv* env)
62396239
env->parse_depth++;
62406240
if (env->parse_depth > ParseDepthLimit)
62416241
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;
6242+
62426243
prev_cc = (CClassNode* )NULL;
62436244
r = fetch_token_in_cc(tok, src, end, env);
62446245
if (r == TK_CHAR && tok->u.c == '^' && tok->escaped == 0) {
@@ -7820,14 +7821,18 @@ static int
78207821
parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
78217822
ScanEnv* env, int group_head)
78227823
{
7823-
int r, len, group = 0;
7824+
int r, len, group;
78247825
Node* qn;
78257826
Node** tp;
7827+
unsigned int parse_depth;
78267828

7829+
group = 0;
78277830
*np = NULL;
78287831
if (tok->type == (enum TokenSyms )term)
78297832
goto end_of_token;
78307833

7834+
parse_depth = env->parse_depth;
7835+
78317836
switch (tok->type) {
78327837
case TK_ALT:
78337838
case TK_EOT:
@@ -8145,6 +8150,10 @@ parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
81458150
if (is_invalid_quantifier_target(*tp))
81468151
return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;
81478152

8153+
parse_depth++;
8154+
if (parse_depth > ParseDepthLimit)
8155+
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;
8156+
81488157
qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper,
81498158
r == TK_INTERVAL);
81508159
CHECK_NULL_RETURN_MEMERR(qn);

0 commit comments

Comments
 (0)