fixed cpantester problem with taintmode unlink() call, now $tmpfile is untainted before

This commit is contained in:
git@daemon.de
2013-07-05 10:10:21 +02:00
parent 90260e757d
commit 2c357f7cf6

View File

@@ -294,6 +294,18 @@ sub read {
$this->{fd}->close(); $this->{fd}->close();
} }
sub untaint {
#
# untaint path's
my ($this, $path) = @_;
if($path =~ /([\w\-\/\\\.:]+\z)/) {
return $1;
}
else {
# fail, return unchanged
return $path;
}
}
sub save { sub save {
# #
@@ -325,8 +337,9 @@ sub save {
$this->addheader($whatsaved); $this->addheader($whatsaved);
$this->addheader($whosaved); $this->addheader($whosaved);
my $tmpfile = File::Spec->catfile(File::Spec->tmpdir(), my $tmpfile = $this->untaint(File::Spec->catfile(File::Spec->tmpdir(),
".vault-" . unpack("L<4", $this->random(16))); ".vault-" . unpack("L<4", $this->random(16))));
unlink $tmpfile; unlink $tmpfile;
my $fd = new FileHandle($tmpfile, 'w') or croak "Could not open tmpfile $tmpfile: $!\n"; my $fd = new FileHandle($tmpfile, 'w') or croak "Could not open tmpfile $tmpfile: $!\n";
$fd->binmode(); $fd->binmode();