summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhobbs <hobbs>2010-12-03 22:30:56 (GMT)
committerhobbs <hobbs>2010-12-03 22:30:56 (GMT)
commit3893991d27719992c4415326bdf02a8730f98e6f (patch)
treead3946eb80fe349a0216aee0bf073a7cea3fe05a
parentea3383df4de871af4befa8a8c0183d7f4b4d1cbd (diff)
downloadtcl-3893991d27719992c4415326bdf02a8730f98e6f.zip
tcl-3893991d27719992c4415326bdf02a8730f98e6f.tar.gz
tcl-3893991d27719992c4415326bdf02a8730f98e6f.tar.bz2
* generic/tclUtil.c (TclReToGlob): add extra check for multiple
inner *s that leads to poor recursive glob matching, defer to original RE instead. tclbench RE var backtrack.
-rw-r--r--ChangeLog14
-rw-r--r--generic/tclUtil.c16
2 files changed, 24 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 135e686..73c01c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,17 @@
+2010-12-03 Jeff Hobbs <jeffh@ActiveState.com>
+
+ * generic/tclUtil.c (TclReToGlob): add extra check for multiple
+ inner *s that leads to poor recursive glob matching, defer to
+ original RE instead. tclbench RE var backtrack.
+
2010-12-03 Jan Nijtmans <nijtmans@users.sf.net>
* generic/tclUtil.c: silence gcc warning when using -Wwrite-strings
* generic/tclStrToD.c: silence gcc warning for non-IEEE platforms
- * win/Makefile.in: [Patch #3116490] cross-compile Tcl mingw32 on unix
- * win/tcl.m4 This makes it possible to cross-compile Tcl/Tk for
- * win/configure.in Windows (either 32-bit or 64-bit) out-of-the-box
- * win/configure on UNIX, using mingw-w64 build tools (If Itcl, tdbc
+ * win/Makefile.in: [Patch #3116490] cross-compile Tcl mingw32 on unix
+ * win/tcl.m4 This makes it possible to cross-compile Tcl/Tk for
+ * win/configure.in Windows (either 32-bit or 64-bit) out-of-the-box
+ * win/configure on UNIX, using mingw-w64 build tools (If Itcl, tdbc
and Thread take over the latest tcl.m4, they can do that too).
2010-12-01 Kevin B. Kenny <kennykb@acm.org>
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 3fc1a35..984ba0a 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtil.c,v 1.122 2010/12/03 09:19:40 nijtmans Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.123 2010/12/03 22:30:56 hobbs Exp $
*/
#include "tclInt.h"
@@ -3328,7 +3328,7 @@ TclReToGlob(
Tcl_DString *dsPtr,
int *exactPtr)
{
- int anchorLeft, anchorRight, lastIsStar;
+ int anchorLeft, anchorRight, lastIsStar, numStars;
char *dsStr, *dsStrStart;
const char *msg, *p, *strEnd;
@@ -3387,6 +3387,7 @@ TclReToGlob(
p = reStr;
anchorRight = 0;
lastIsStar = 0;
+ numStars = 0;
if (*p == '^') {
anchorLeft = 1;
@@ -3450,6 +3451,7 @@ TclReToGlob(
if (!lastIsStar) {
*dsStr++ = '*';
lastIsStar = 1;
+ numStars++;
}
continue;
} else if (p[1] == '+') {
@@ -3457,6 +3459,7 @@ TclReToGlob(
*dsStr++ = '?';
*dsStr++ = '*';
lastIsStar = 1;
+ numStars++;
continue;
}
}
@@ -3480,6 +3483,15 @@ TclReToGlob(
}
lastIsStar = 0;
}
+ if (numStars > 1) {
+ /*
+ * Heuristic: if >1 non-anchoring *, the risk is large that glob
+ * matching is slower than the RE engine, so report invalid.
+ */
+ msg = "excessive recursive glob backtrack potential";
+ goto invalidGlob;
+ }
+
if (!anchorRight && !lastIsStar) {
*dsStr++ = '*';
}