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