Skip to content

Commit

Permalink
always enforce expression complexity limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkelmann committed Sep 1, 2023
1 parent f82ebc5 commit 1431e9c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/cwe_checker_lib/src/analysis/expression_propagation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,20 @@ pub fn propagate_input_expressions(
var,
value: expression,
} => {
// insert known input expressions
for (input_var, input_expr) in insertable_expressions.iter() {
expression.substitute_input_var(input_var, input_expr);
// Extend the considered expression with already known expressions.
let mut extended_expression = expression.clone();
for input_var in expression.input_vars().into_iter() {
if let Some(expr) = insertable_expressions.get(input_var) {
// We limit the complexity of expressions to insert.
// This prevents extremely large expressions that can lead to extremely high RAM usage.
// FIXME: Right now this limit is quite arbitrary. Maybe there is a better way to achieve the same result?
if expr.recursion_depth() < 10 {
extended_expression.substitute_input_var(input_var, expr)
}
}
}
extended_expression.substitute_trivial_operations();
*expression = extended_expression;
// expressions dependent on the assigned variable are no longer insertable
insertable_expressions.retain(|input_var, input_expr| {
input_var != var && !input_expr.input_vars().into_iter().any(|x| x == var)
Expand Down

0 comments on commit 1431e9c

Please sign in to comment.