1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!./perl -t
BEGIN {
chdir 't';
@INC = '../lib';
require './test.pl';
}
plan tests => 13;
my $Perl = which_perl();
my $warning;
local $SIG{__WARN__} = sub { $warning = join "\n", @_; };
my $Tmsg = 'while running with -t switch';
is( ${^TAINT}, -1, '${^TAINT} == -1' );
my $out = `$Perl -le "print q(Hello)"`;
is( $out, "Hello\n", '`` worked' );
like( $warning, qr/^Insecure .* $Tmsg/, ' taint warn' );
{
no warnings 'taint';
$warning = '';
my $out = `$Perl -le "print q(Hello)"`;
is( $out, "Hello\n", '`` worked' );
is( $warning, '', ' no warnings "taint"' );
}
# Get ourselves a tainted variable.
my $filename = tempfile();
$file = $0;
$file =~ s/.*/$filename/;
ok( open(FILE, ">$file"), 'open >' ) or DIE $!;
print FILE "Stuff\n";
close FILE;
like( $warning, qr/^Insecure dependency in open $Tmsg/, 'open > taint warn' );
ok( -e $file, ' file written' );
unlink($file);
like( $warning, qr/^Insecure dependency in unlink $Tmsg/,
'unlink() taint warn' );
ok( !-e $file, 'unlink worked' );
ok( !$^W, "-t doesn't enable regular warnings" );
mkdir('ttdir');
open(FH,'>','ttdir/ttest.pl')or DIE $!;
print FH 'return 42';
close FH or DIE $!;
SKIP: {
($^O eq 'MSWin32') || skip('skip tainted do test with \ separator');
my $test = 0;
$test = do '.\ttdir/ttest.pl';
is($test, 42, 'Could "do" .\ttdir/ttest.pl');
}
{
my $test = 0;
$test = do './ttdir/ttest.pl';
is($test, 42, 'Could "do" ./ttdir/ttest.pl');
}
unlink ('./ttdir/ttest.pl');
rmdir ('ttdir');
|