Additional simplification of evaluate_expression()

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2012-07-08 07:48:27 -07:00
parent 3c2385de06
commit 9f4ca3ebc5

View File

@ -1688,7 +1688,7 @@ sub evaluate_expression( $$$ ) {
exists $capdesc{$var} ? have_capability( $var ) : 0 ); exists $capdesc{$var} ? have_capability( $var ) : 0 );
$val = 0 unless defined $val; $val = 0 unless defined $val;
$val = "'$val'" unless $val =~ /^-?\d+$/; $val = "'$val'" unless $val =~ /^-?\d+$/;
$expression = join( '', $first, $val, $rest ); $expression = join( '', $first, $val || 0, $rest );
cond_error( "Variable Expansion Loop" , $filename, $linenumber ) if ++$count > 100; cond_error( "Variable Expansion Loop" , $filename, $linenumber ) if ++$count > 100;
} }
@ -1707,14 +1707,11 @@ sub evaluate_expression( $$$ ) {
$expression = join( '', $first, $val || 0, $rest ); $expression = join( '', $first, $val || 0, $rest );
} }
if ( $expression =~ /^\s*(\d+)\s*$/ || $expression =~ /\s*'(.*?)'\s*$/ ) { $expression =~ s/^\s*(.+)\s*$/$1/;
unless ( $expression =~ /^\d+$/ ) {
# #
# Simple one-term expression -- don't compile it # Not a simple one-term expression -- compile it
#
$val = $1;
} else {
#
# Not a simple one-term expression
# #
$val = eval qq(package Shorewall::User;\nuse strict;\n# line $linenumber "$filename"\n$expression); $val = eval qq(package Shorewall::User;\nuse strict;\n# line $linenumber "$filename"\n$expression);