Avoid a call to eval() for simple expressions

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2012-07-06 07:26:54 -07:00
parent e9d8228b6f
commit 83df8a4e39

View File

@ -1708,11 +1708,23 @@ sub evaluate_expression( $$$ ) {
$expression = join( '', $first, $val, $rest ); $expression = join( '', $first, $val, $rest );
} }
my $val = eval qq(package Shorewall::User;\nuse strict;\n# line $linenumber "$filename"\n$expression); my $val;
unless ( $val ) { if ( $expression =~ /^\s*(\d+)\s*$/ || $expression =~ /\s*'(.*?)'\s*$/ ) {
cond_error( "Couldn't parse expression: $@" , $filename, $linenumber ) if $@; #
cond_error( "Undefined expression" , $filename, $linenumber ) unless defined $val; # Simple one-term expression -- don't 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);
unless ( $val ) {
cond_error( "Couldn't parse expression: $@" , $filename, $linenumber ) if $@;
cond_error( "Undefined expression" , $filename, $linenumber ) unless defined $val;
}
} }
$val; $val;