[ZPT] CVS: Packages/TAL - TALInterpreter.py:1.44

guido@digicool.com guido@digicool.com
Fri, 18 May 2001 14:17:05 -0400 (EDT)


Update of /cvs-repository/Packages/TAL
In directory korak.digicool.com:/tmp/cvs-serv23173

Modified Files:
	TALInterpreter.py 
Log Message:
do_userMacro(): Implement a limit to macro expansion nesting.  It was
quite easy to accidentally set off an infinite recursion here.



--- Updated File TALInterpreter.py in package Packages/TAL --
--- TALInterpreter.py	2001/05/18 00:42:07	1.43
+++ TALInterpreter.py	2001/05/18 18:17:02	1.44
@@ -152,7 +152,7 @@
 
     def __init__(self, program, macros, engine, stream=None,
                  debug=0, wrap=60, metal=1, tal=1, showtal=-1,
-                 strictinsert=1):
+                 strictinsert=1, stackLimit=100):
         self.program = program
         self.macros = macros
         self.engine = engine
@@ -168,6 +168,7 @@
             showtal = (not tal)
         self.showtal = showtal
         self.strictinsert = strictinsert
+        self.stackLimit = stackLimit
         self.html = 0
         self.endsep = "/>"
         self.macroStack = []
@@ -448,6 +449,9 @@
         if mode != (self.html and "html" or "xml"):
             raise METALError("macro %s has incompatible mode %s" %
                              (`macroName`, `mode`), self.position)
+        if len(self.macroStack) >= self.stackLimit:
+            raise METALError("macro nesting limit (%d) exceeded "
+                             "by macro %s" % (self.stackLimit, `macroName`))
         self.macroStack.append((macroName, compiledSlots))
         self.interpret(macro)
         self.macroStack.pop()