summaryrefslogtreecommitdiffstats
path: root/generic/regc_nfa.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2007-11-15 21:38:49 (GMT)
committerdgp <dgp@users.sourceforge.net>2007-11-15 21:38:49 (GMT)
commitc1ae9630391876566550efb6ab1eb92a9e21f560 (patch)
tree3ef115aa857c83be56bd4c069f77af10b15a7b6c /generic/regc_nfa.c
parent0d571ed33320f761a463464e4ed2886eee487898 (diff)
downloadtcl-c1ae9630391876566550efb6ab1eb92a9e21f560.zip
tcl-c1ae9630391876566550efb6ab1eb92a9e21f560.tar.gz
tcl-c1ae9630391876566550efb6ab1eb92a9e21f560.tar.bz2
* generic/regc_nfa.c: Fixed infinite loop in the regexp compiler.
[Bug 1810038].
Diffstat (limited to 'generic/regc_nfa.c')
-rw-r--r--generic/regc_nfa.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c
index c5d7bc9..741887f 100644
--- a/generic/regc_nfa.c
+++ b/generic/regc_nfa.c
@@ -859,6 +859,25 @@ pull(
}
/*
+ * DGP 2007-11-15: Cloning a state with a circular constraint on its list
+ * of outs can lead to trouble [Bug 1810038], so get rid of them first.
+ */
+
+ for (a = from->outs; a != NULL; a = nexta) {
+ nexta = a->outchain;
+ switch (a->type) {
+ case '^':
+ case '$':
+ case BEHIND:
+ case AHEAD:
+ if (from == a->to) {
+ freearc(nfa, a);
+ }
+ break;
+ }
+ }
+
+ /*
* First, clone from state if necessary to avoid other outarcs.
*/
@@ -997,6 +1016,28 @@ push(
}
/*
+ * DGP 2007-11-15: Here we duplicate the same protections as appear
+ * in pull() above to avoid troubles with cloning a state with a
+ * circular constraint on its list of ins. It is not clear whether
+ * this is necessary, or is protecting against a "can't happen".
+ * Any test case that actually leads to a freearc() call here would
+ * be a welcome addition to the test suite.
+ */
+
+ for (a = to->ins; a != NULL; a = nexta) {
+ nexta = a->inchain;
+ switch (a->type) {
+ case '^':
+ case '$':
+ case BEHIND:
+ case AHEAD:
+ if (a->from == to) {
+ freearc(nfa, a);
+ }
+ break;
+ }
+ }
+ /*
* First, clone to state if necessary to avoid other inarcs.
*/