diff options
author | dkf <dkf@noemail.net> | 2008-07-01 14:29:11 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2008-07-01 14:29:11 (GMT) |
commit | a84aecb3556380831891869176455bf73a93626e (patch) | |
tree | 155be98abe3f09f2c334dd275fd725cdaf10506d /generic/regc_nfa.c | |
parent | 0685b815bc2dec5e16c0592a1dba4de8b3743dc3 (diff) | |
download | tcl-a84aecb3556380831891869176455bf73a93626e.zip tcl-a84aecb3556380831891869176455bf73a93626e.tar.gz tcl-a84aecb3556380831891869176455bf73a93626e.tar.bz2 |
Add focussed stack limiting to the RE compiler. Tuning might not yet be right
but it passes everything normally checked in the test suite. [Bug 1905562]
FossilOrigin-Name: 1ab85d8c7df2ba9745aba4ef87ae8afc26e9b04d
Diffstat (limited to 'generic/regc_nfa.c')
-rw-r--r-- | generic/regc_nfa.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c index d8cbd82..4fb3ea6 100644 --- a/generic/regc_nfa.c +++ b/generic/regc_nfa.c @@ -725,7 +725,7 @@ dupnfa( } stop->tmp = to; - duptraverse(nfa, start, from); + duptraverse(nfa, start, from, 0); /* done, except for clearing out the tmp pointers */ stop->tmp = NULL; @@ -740,7 +740,8 @@ static void duptraverse( struct nfa *nfa, struct state *s, - struct state *stmp) /* s's duplicate, or NULL */ + struct state *stmp, /* s's duplicate, or NULL */ + int depth) { struct arc *a; @@ -754,8 +755,18 @@ duptraverse( return; } + /* + * Arbitrary depth limit. Needs tuning, but this value is sufficient to + * make all normal tests (not reg-33.14) pass. + */ +#define DUPTRAVERSE_MAX_DEPTH 500 + + if (depth++ > DUPTRAVERSE_MAX_DEPTH) { + NERR(REG_ESPACE); + } + for (a=s->outs ; a!=NULL && !NISERR() ; a=a->outchain) { - duptraverse(nfa, a->to, NULL); + duptraverse(nfa, a->to, NULL, depth); if (NISERR()) { break; } |