diff options
author | Pascal Terjan <pterjan@mandriva.org> | 2009-03-10 17:19:35 +0000 |
---|---|---|
committer | Pascal Terjan <pterjan@mandriva.org> | 2009-03-10 17:19:35 +0000 |
commit | d1aaeb46ed5fc7609199c491627abdc16970d0b2 (patch) | |
tree | bdd4da9a93947e458e68d16171f2eb6ecad03c9f /lib/MDK/Common | |
parent | 3c47af81cc0fcd39a403feccb72e281ea87f1f24 (diff) | |
download | perl-MDK-Common-d1aaeb46ed5fc7609199c491627abdc16970d0b2.tar perl-MDK-Common-d1aaeb46ed5fc7609199c491627abdc16970d0b2.tar.gz perl-MDK-Common-d1aaeb46ed5fc7609199c491627abdc16970d0b2.tar.bz2 perl-MDK-Common-d1aaeb46ed5fc7609199c491627abdc16970d0b2.tar.xz perl-MDK-Common-d1aaeb46ed5fc7609199c491627abdc16970d0b2.zip |
protect various chars in setExportedVarsInSh and setExportedVarsInCsh
Diffstat (limited to 'lib/MDK/Common')
-rw-r--r-- | lib/MDK/Common/System.pm | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/MDK/Common/System.pm b/lib/MDK/Common/System.pm index e3d514d..419a8d4 100644 --- a/lib/MDK/Common/System.pm +++ b/lib/MDK/Common/System.pm @@ -368,20 +368,22 @@ sub setVarsInSh { setVarsInShMode($file, 0777 ^ umask(), $l, @fields); } +sub quoteForSh { + my ($val) = @_; + if ($val =~ /["`\$]/) { + $val =~ s/(')/\\$1/g; + $val = qq('$val'); + } elsif ($val =~ /[\(\)'|\s\\;<>&#\[\]~{}*?]/) { + $val = qq("$val"); + } + $val; +} + sub setVarsInShMode { my ($file, $mod, $l, @fields) = @_; @fields = keys %$l unless @fields; my $string = join('', - map { - my $val = $l->{$_}; - if ($val =~ /["`\$]/) { - $val =~ s/(')/\\$1/g; - $val = qq('$val'); - } elsif ($val =~ /[\(\)'|\s\\;<>&#\[\]~{}*?]/) { - $val = qq("$val"); - } - "$_=$val\n"; - } grep { $l->{$_} } @fields + map { "$_=".quoteForSh($l->{$_})."\n" } grep { $l->{$_} } @fields ); if ($file =~ m!^/home/!) { MDK::Common::File::secured_output($file, $string); @@ -397,7 +399,7 @@ sub setExportedVarsInSh { @fields = keys %$l unless @fields; MDK::Common::File::output($file, - (map { $l->{$_} ? "$_=$l->{$_}\n" : () } @fields), + (map { $l->{$_} ? "$_=".quoteForSh($l->{$_})."\n" : () } @fields), @fields ? "export " . join(" ", @fields) . "\n" : (), ); } @@ -406,7 +408,7 @@ sub setExportedVarsInCsh { my ($file, $l, @fields) = @_; @fields = keys %$l unless @fields; - MDK::Common::File::output($file, map { $l->{$_} ? "setenv $_ $l->{$_}\n" : () } @fields); + MDK::Common::File::output($file, map { $l->{$_} ? "setenv $_ ".quoteForSh($l->{$_})."\n" : () } @fields); } sub template2file { |