Acme-TaintTest
view release on metacpan or search on metacpan
# Default options
my %options = (
"CLEANUP" => 0, # Remove directory on exit
"DIR" => '', # Root directory
"TMPDIR" => 0, # Use tempdir with template
);
# Check to see whether we have an odd or even number of arguments
my ($maybe_template, $args) = File::Temp::_parse_args(@_);
carp "options args->{DIR} $args->{DIR}" if tainted($args->{DIR});
my $template = @$maybe_template ? $maybe_template->[0] : undef;
# Read the options and merge with defaults
%options = (%options, %$args);
carp "options dir 1 $options{DIR}" if tainted($options{'DIR'});
# Modify or generate the template
# Deal with the DIR and TMPDIR options
if (defined $template) {
carp "tempdir called with tainted template $template" if tainted($template);
# Need to strip directory path if using DIR or TMPDIR
if ($options{'TMPDIR'} || $options{'DIR'}) {
carp "options dir 2 $options{DIR}" if tainted($options{'DIR'});
# Strip parent directory from the filename
#
# There is no filename at the end
my ($volume, $directories, undef) = File::Spec->splitpath( $template, 1);
# Last directory is then our template
$template = (File::Spec->splitdir($directories))[-1];
carp "tempdir after spltdir tainted template $template" if tainted($template);
# Prepend the supplied directory or temp dir
if ($options{"DIR"}) {
carp "options dir 3 $options{DIR}" if tainted($options{"DIR"});
carp "tempdir before cattdir 1 tainted template $template" if tainted($template);
}
carp "tempdir after cattdir if block tainted template $template" if tainted($template);
# Create the directory
my $tempdir;
my $suffixlen = 0;
my $errstr;
croak "Error in tempdir() using $template: $errstr"
unless ((undef, $tempdir) = File::Temp::_gettemp($template,
"open" => 0,
"mkdir"=> 1 ,
"suffixlen" => $suffixlen,
"ErrStr" => \$errstr,
) );
# Install exit handler; must be dynamic to get lexical
if ( $options{'CLEANUP'} && -d $tempdir) {
_deferred_unlink(undef, $tempdir, 1);
}
# Return the dir name
return $tempdir;
}
### MonkeyPatch the Unix implementation of File::Spec->catdir
sub _patched_pp_canonpath {
my ($self,$path) = @_;
( run in 1.359 second using v1.01-cache-2.11-cpan-d80b1682f3f )