More param handling fixes

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2015-10-28 09:37:52 -07:00
parent 081cf30447
commit 3873ebe06a

View File

@ -5188,17 +5188,14 @@ sub get_params( $ ) {
$shell = BASH; $shell = BASH;
for ( @params ) { for ( @params ) {
my $var = $1;
unless ( $var =~ /\(/ ) {
if ( /^declare -x (.*?)="(.*[^\\])"$/ ) {
$params{$var} = $2 unless $1 eq '_';
} elsif ( /^declare -x (.*?)="(.*)$/ ) {
$params{$variable=$var} = $2 eq '"' ? '' : "${2}\n";
} elsif ( /^declare -x (.*)\s+$/ || /^declare -x (.*)=""$/ ) {
$params{$var} = '';
} else {
chomp; chomp;
if ( /^declare -x (.*?)="(.*[^\\])"$/ ) {
$params{$1} = $2 unless $1 eq '_';
} elsif ( /^declare -x (.*?)="(.*)$/ ) {
$params{$variable=$1} = $2 eq '"' ? '' : "${2}\n";
} elsif ( /^declare -x (.*)\s+$/ || /^declare -x (.*)=""$/ ) {
$params{$1} = '';
} else {
if ($variable) { if ($variable) {
s/"$//; s/"$//;
$params{$variable} .= $_; $params{$variable} .= $_;
@ -5207,7 +5204,6 @@ sub get_params( $ ) {
} }
} }
} }
}
} elsif ( $params[0] =~ /^export .*?="/ || $params[0] =~ /^export [^\s=]+\s*$/ ) { } elsif ( $params[0] =~ /^export .*?="/ || $params[0] =~ /^export [^\s=]+\s*$/ ) {
# #
# getparams interpreted by older (e.g., RHEL 5) Bash # getparams interpreted by older (e.g., RHEL 5) Bash
@ -5220,17 +5216,14 @@ sub get_params( $ ) {
$shell = OLDBASH; $shell = OLDBASH;
for ( @params ) { for ( @params ) {
my $var = $1;
unless ( $var =~ /\(/ ) {
if ( /^export (.*?)="(.*[^\\])"$/ ) {
$params{$var} = $2 unless $1 eq '_';
} elsif ( /^export (.*?)="(.*)$/ ) {
$params{$variable=$var} = $2 eq '"' ? '' : "${2}\n";
} elsif ( /^export ([^\s=]+)\s*$/ || /^export (.*)=""$/ ) {
$params{$var} = '';
} else {
chomp; chomp;
if ( /^export (.*?)="(.*[^\\])"$/ ) {
$params{$1} = $2 unless $1 eq '_';
} elsif ( /^export (.*?)="(.*)$/ ) {
$params{$variable=$1} = $2 eq '"' ? '' : "${2}\n";
} elsif ( /^export ([^\s=]+)\s*$/ || /^export (.*)=""$/ ) {
$params{$1} = '';
} else {
if ($variable) { if ($variable) {
s/"$//; s/"$//;
$params{$variable} .= $_; $params{$variable} .= $_;
@ -5239,7 +5232,6 @@ sub get_params( $ ) {
} }
} }
} }
}
} else { } else {
# #
# getparams was interpreted by dash/ash/busybox # getparams was interpreted by dash/ash/busybox
@ -5251,6 +5243,7 @@ sub get_params( $ ) {
$shell = ASH; $shell = ASH;
for ( @params ) { for ( @params ) {
chomp;
if ( /^export (.*?)='(.*'"'"')$/ ) { if ( /^export (.*?)='(.*'"'"')$/ ) {
$params{$variable=$1}="${2}\n"; $params{$variable=$1}="${2}\n";
} elsif ( /^export (.*?)='(.*)'$/ ) { } elsif ( /^export (.*?)='(.*)'$/ ) {
@ -5258,7 +5251,6 @@ sub get_params( $ ) {
} elsif ( /^export (.*?)='(.*)$/ ) { } elsif ( /^export (.*?)='(.*)$/ ) {
$params{$variable=$1}="${2}\n"; $params{$variable=$1}="${2}\n";
} else { } else {
chomp;
if ($variable) { if ($variable) {
s/'$//; s/'$//;
$params{$variable} .= $_; $params{$variable} .= $_;
@ -5270,11 +5262,15 @@ sub get_params( $ ) {
} }
for ( keys %params ) { for ( keys %params ) {
if ( /[^\w]/ ) {
delete $params{$_}
} else {
unless ( $_ eq 'SHOREWALL_INIT_SCRIPT' ) { unless ( $_ eq 'SHOREWALL_INIT_SCRIPT' ) {
fatal_error "The variable name $_ is reserved and may not be set in the params file" fatal_error "The variable name $_ is reserved and may not be set in the params file"
if /^SW_/ || /^SHOREWALL_/ || ( exists $config{$_} && ! exists $ENV{$_} ) || exists $reserved{$_}; if /^SW_/ || /^SHOREWALL_/ || ( exists $config{$_} && ! exists $ENV{$_} ) || exists $reserved{$_};
} }
} }
}
if ( $debug ) { if ( $debug ) {
print "PARAMS:\n"; print "PARAMS:\n";
@ -5322,6 +5318,8 @@ sub export_params() {
next if exists $compiler_params{$param}; next if exists $compiler_params{$param};
my $value = $params{$param}; my $value = $params{$param};
chomp $value;
# #
# Values in %params are generated from the output of 'export -p'. # Values in %params are generated from the output of 'export -p'.
# The different shells have different conventions for delimiting # The different shells have different conventions for delimiting
@ -5332,6 +5330,8 @@ sub export_params() {
$value =~ s/\\"/"/g; $value =~ s/\\"/"/g;
} elsif ( $shell == OLDBASH ) { } elsif ( $shell == OLDBASH ) {
$value =~ s/\\'/'/g; $value =~ s/\\'/'/g;
$value =~ s/\\"/"/g;
$value =~ s/\\\\/\\/g;
} else { } else {
$value =~ s/'"'"'/'/g; $value =~ s/'"'"'/'/g;
} }
@ -5344,7 +5344,9 @@ sub export_params() {
# #
# We will use double quotes and escape embedded quotes with \. # We will use double quotes and escape embedded quotes with \.
# #
if ( $value =~ /[\s()['"]/ ) { if ( $value =~ /^"[^"]*"$/ ) {
emit "$param=$value";
} elsif ( $value =~ /[\s()['"]/ ) {
$value =~ s/"/\\"/g; $value =~ s/"/\\"/g;
emit "$param='$value'"; emit "$param='$value'";
} else { } else {