POSIX taint tests
[p5sagit/p5-mst-13.2.git] / ext / POSIX / t / taint.t
1 #!./perl -Tw
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require Config; import Config;
7     if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
8         print "1..0\n";
9         exit 0;
10     }
11 }
12
13 require "./test.pl";
14 use Scalar::Util qw/tainted/;
15 plan(tests => 5);
16
17
18 use POSIX qw(fcntl_h open read mkfifo);
19 use strict ;
20
21 $| = 1;
22
23 my $buffer;
24 my @buffer;
25 my $testfd;
26
27 # Sources of taint:
28 #   The empty tainted value, for tainting strings
29
30 my $TAINT = substr($^X, 0, 0);
31
32 eval { mkfifo($TAINT. "TEST", 0) };
33 ok($@ =~ /^Insecure dependency/,              'mkfifo with tainted data');
34
35 eval { $testfd = open($TAINT. "TEST", O_WRONLY, 0) };
36 ok($@ =~ /^Insecure dependency/,              'open with tainted data');
37
38 eval { $testfd = open("TEST", O_RDONLY, 0) };
39 ok($@ eq "",                                  'open with untainted data');
40
41 read($testfd, $buffer, 2) if $testfd > 2;
42 is( $buffer, "#!",                                '    read' );
43 ok(tainted($buffer),                          '    scalar tainted');
44 read($testfd, $buffer[1], 2) if $testfd > 2;
45
46 #is( $buffer[1], "./",                        '    read' );
47 #ok(tainted($buffer[1]),                       '    array element tainted');