Skip to content

Commit

Permalink
fix #147: Stack Exhaustion Problem caused by some parsing functions i…
Browse files Browse the repository at this point in the history
…n regcomp.c making recursive calls to themselves.
  • Loading branch information
K.Kosako committed Jul 29, 2019
1 parent 2b6b502 commit 4097828
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/regparse.c
Expand Up @@ -6239,6 +6239,7 @@ parse_char_class(Node** np, PToken* tok, UChar** src, UChar* end, ScanEnv* env)
env->parse_depth++;
if (env->parse_depth > ParseDepthLimit)
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;

prev_cc = (CClassNode* )NULL;
r = fetch_token_in_cc(tok, src, end, env);
if (r == TK_CHAR && tok->u.c == '^' && tok->escaped == 0) {
Expand Down Expand Up @@ -7820,14 +7821,18 @@ static int
parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
ScanEnv* env, int group_head)
{
int r, len, group = 0;
int r, len, group;
Node* qn;
Node** tp;
unsigned int parse_depth;

group = 0;
*np = NULL;
if (tok->type == (enum TokenSyms )term)
goto end_of_token;

parse_depth = env->parse_depth;

switch (tok->type) {
case TK_ALT:
case TK_EOT:
Expand Down Expand Up @@ -8145,6 +8150,10 @@ parse_exp(Node** np, PToken* tok, int term, UChar** src, UChar* end,
if (is_invalid_quantifier_target(*tp))
return ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID;

parse_depth++;
if (parse_depth > ParseDepthLimit)
return ONIGERR_PARSE_DEPTH_LIMIT_OVER;

qn = node_new_quantifier(tok->u.repeat.lower, tok->u.repeat.upper,
r == TK_INTERVAL);
CHECK_NULL_RETURN_MEMERR(qn);
Expand Down

0 comments on commit 4097828

Please sign in to comment.