mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
Protect the Parser against recursive parsing issues
This commit is contained in:
+12
-1
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
class Twig_Parser implements Twig_ParserInterface
|
||||
{
|
||||
protected $stack = array();
|
||||
protected $stream;
|
||||
protected $parent;
|
||||
protected $handlers;
|
||||
@@ -61,6 +62,10 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
*/
|
||||
public function parse(Twig_TokenStream $stream)
|
||||
{
|
||||
$vars = get_object_vars($this);
|
||||
unset($vars['stack'], $vars['env']);
|
||||
$this->stack[] = $vars;
|
||||
|
||||
$this->tmpVarCount = 0;
|
||||
|
||||
// tag handlers
|
||||
@@ -102,7 +107,13 @@ class Twig_Parser implements Twig_ParserInterface
|
||||
|
||||
$traverser = new Twig_NodeTraverser($this->env, $this->visitors);
|
||||
|
||||
return $traverser->traverse($node);
|
||||
$node = $traverser->traverse($node);
|
||||
|
||||
foreach (array_pop($this->stack) as $key => $val) {
|
||||
$this->$key = $val;
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
public function subparse($test, $dropNeedle = false)
|
||||
|
||||
Reference in New Issue
Block a user