Limit expression/statement nesting depths.

This commit is contained in:
Stephen Chung
2020-05-18 19:32:22 +08:00
parent f4a528a88a
commit 1824dced69
7 changed files with 513 additions and 198 deletions

View File

@@ -444,7 +444,14 @@ impl Engine {
optimization_level: OptimizationLevel,
) -> Result<AST, Box<ParseError>> {
let stream = lex(scripts);
parse(&mut stream.peekable(), self, scope, optimization_level)
parse(
&mut stream.peekable(),
self,
scope,
optimization_level,
(self.max_expr_depth, self.max_function_expr_depth),
)
}
/// Read the contents of a file into a string.
@@ -571,6 +578,7 @@ impl Engine {
self,
&scope,
OptimizationLevel::None,
self.max_expr_depth,
)?;
// Handle null - map to ()
@@ -654,7 +662,13 @@ impl Engine {
{
let mut peekable = stream.peekable();
parse_global_expr(&mut peekable, self, scope, self.optimization_level)
parse_global_expr(
&mut peekable,
self,
scope,
self.optimization_level,
self.max_expr_depth,
)
}
}
@@ -805,8 +819,14 @@ impl Engine {
) -> Result<T, Box<EvalAltResult>> {
let scripts = [script];
let stream = lex(&scripts);
// Since the AST will be thrown away afterwards, don't bother to optimize it
let ast = parse_global_expr(&mut stream.peekable(), self, scope, OptimizationLevel::None)?;
let ast = parse_global_expr(
&mut stream.peekable(),
self,
scope,
self.optimization_level,
self.max_expr_depth,
)?;
self.eval_ast_with_scope(scope, &ast)
}
@@ -931,8 +951,13 @@ impl Engine {
let scripts = [script];
let stream = lex(&scripts);
// Since the AST will be thrown away afterwards, don't bother to optimize it
let ast = parse(&mut stream.peekable(), self, scope, OptimizationLevel::None)?;
let ast = parse(
&mut stream.peekable(),
self,
scope,
self.optimization_level,
(self.max_expr_depth, self.max_function_expr_depth),
)?;
self.consume_ast_with_scope(scope, &ast)
}