Make expression evaluation more deterministic.

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2012-12-04 18:10:19 -08:00
parent 2fbbc70e83
commit c61c9ba7eb

View File

@ -1943,10 +1943,16 @@ sub evaluate_expression( $$$ ) {
$val = ( exists $variables{$var} ? $variables{$var} : $val = ( exists $variables{$var} ? $variables{$var} :
exists $actparms{$var} ? ( $var ? $actparms{$var} : $actparms{0}->{name} ) : exists $actparms{$var} ? ( $var ? $actparms{$var} : $actparms{0}->{name} ) :
exists $capdesc{$var} ? have_capability( $var ) : 0 ); exists $capdesc{$var} ? have_capability( $var ) : '' );
$val = 0 unless defined $val; $val = '' unless defined $val;
if ( $val eq '' ) {
$val = "''" unless $first =~ /['"]$/;
} else {
$val = "'$val'" unless $val =~ /^-?\d+$/; $val = "'$val'" unless $val =~ /^-?\d+$/;
$expression = join( '', $first, $val || 0, $rest ); }
$expression = join( '', $first, $val, $rest );
cond_error( "Variable Expansion Loop" , $filename, $linenumber ) if ++$count > 100; cond_error( "Variable Expansion Loop" , $filename, $linenumber ) if ++$count > 100;
} }
@ -1967,12 +1973,13 @@ sub evaluate_expression( $$$ ) {
cond_error "Unknown capability ($cap)", $filename, $linenumber; cond_error "Unknown capability ($cap)", $filename, $linenumber;
} }
$expression = join( '', $first, $val || 0, $rest ); $expression = join( '', $first, $val, $rest );
} }
$expression =~ s/^\s*(.+)\s*$/$1/; $expression =~ s/^\s*(.+)\s*$/$1/;
unless ( $expression =~ /^\d+$/ ) { unless ( $expression =~ /^\d+$/ ) {
print "EXPR=> $expression\n" if $debug;
# #
# Not a simple one-term expression -- compile it # Not a simple one-term expression -- compile it
# #