3 # Taint tests by Tom Phoenix <rootbeer@teleport.com>.
5 # I don't claim to know all about tainting. If anyone sees
6 # tests that I've missed here, please add them. But this is
7 # better than having no tests at all, right?
17 use File::Spec::Functions;
23 # You have to do it this way or VMS will get confused.
24 print $ok ? "ok $test - $name\n" : "not ok $test - $name\n";
26 printf "# Failed test at line %d\n", (caller)[2] unless $ok;
35 use vars qw($ipcsysv); # did we manage to load IPC::SysV?
38 if ($^O eq 'VMS' && !defined($Config{d_setenv})) {
39 $ENV{PATH} = $ENV{PATH};
40 $ENV{TERM} = $ENV{TERM} ne ''? $ENV{TERM} : 'dummy';
42 if ($Config{'extensions'} =~ /\bIPC\/SysV\b/
43 && ($Config{d_shm} || $Config{d_msg})) {
44 eval { require IPC::SysV };
47 IPC::SysV->import(qw(IPC_PRIVATE IPC_RMID IPC_CREAT S_IRWXU IPC_NOWAIT));
52 my $Is_MacOS = $^O eq 'MacOS';
53 my $Is_VMS = $^O eq 'VMS';
54 my $Is_MSWin32 = $^O eq 'MSWin32';
55 my $Is_NetWare = $^O eq 'NetWare';
56 my $Is_Dos = $^O eq 'dos';
57 my $Is_Cygwin = $^O eq 'cygwin';
58 my $Invoke_Perl = $Is_VMS ? 'MCR Sys$Disk:[]Perl.' :
59 ($Is_MSWin32 ? '.\perl' :
61 ($Is_NetWare ? 'perl' : './perl'));
62 my @MoreEnv = qw/IFS CDPATH ENV BASH_ENV/;
66 for $x ('DCL$PATH', @MoreEnv) {
67 ($old{$x}) = $ENV{$x} =~ /^(.*)$/ if exists $ENV{$x};
71 \$ENV{PATH} = '' if $Config{d_setenv};
72 warn "# Note: logical name 'PATH' may have been deleted\n";
73 \@ENV{keys %old} = values %old;
79 # The empty tainted value, for tainting strings
80 my $TAINT = substr($^X, 0, 0);
81 # A tainted zero, useful for tainting numbers
82 my $TAINT0 = 0 + $TAINT;
84 # This taints each argument passed. All must be lvalues.
85 # Side effect: It also stringifies them. :-(
87 for (@_) { $_ .= $TAINT }
90 # How to identify taint when you see it
92 not eval { join("",@_), kill 0; 1 };
98 for (@_) { return 0 unless tainted $_ }
103 my($serial, $boolean, $diag) = @_;
105 print "ok $serial\n";
107 print "not ok $serial\n";
108 for (split m/^/m, $diag) {
113 or substr($diag, -1) eq "\n";
117 # We need an external program to call.
118 my $ECHO = ($Is_MSWin32 ? ".\\echo$$" : $Is_MacOS ? ":echo$$" : ($Is_NetWare ? "echo$$" : "./echo$$"));
120 open PROG, "> $ECHO" or die "Can't create $ECHO: $!";
121 print PROG 'print "@ARGV\n"', "\n";
123 my $echo = "$Invoke_Perl $ECHO";
125 my $TEST = catfile(curdir(), 'TEST');
129 # First, let's make sure that Perl is checking the dangerous
130 # environment variables. Maybe they aren't set yet, so we'll
131 # taint them ourselves.
133 $ENV{'DCL$PATH'} = '' if $Is_VMS;
136 delete @ENV{@MoreEnv};
139 if ($Is_Cygwin && ! -f 'cygwin1.dll') {
140 system("/usr/bin/cp /usr/bin/cygwin1.dll .") &&
141 die "$0: failed to cp cygwin1.dll: $!\n";
142 END { unlink "cygwin1.dll" } # yes, done for all platforms...
145 test 1, eval { `$echo 1` } eq "1\n";
147 if ($Is_MSWin32 || $Is_NetWare || $Is_VMS || $Is_Dos || $Is_MacOS) {
148 print "# Environment tainting tests skipped\n";
149 for (2..5) { print "ok $_\n" }
152 my @vars = ('PATH', @MoreEnv);
153 while (my $v = $vars[0]) {
154 local $ENV{$v} = $TAINT;
155 last if eval { `$echo 1` };
156 last unless $@ =~ /^Insecure \$ENV{$v}/;
159 test 2, !@vars, "\$$vars[0]";
161 # tainted $TERM is unsafe only if it contains metachars
163 $ENV{TERM} = 'e=mc2';
164 test 3, eval { `$echo 1` } eq "1\n";
165 $ENV{TERM} = 'e=mc2' . $TAINT;
166 test 4, eval { `$echo 1` } eq '';
167 test 5, $@ =~ /^Insecure \$ENV{TERM}/, $@;
171 if ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32 || $Is_NetWare || $Is_Dos) {
172 print "# all directories are writeable\n";
175 $tmp = (grep { defined and -d and (stat _)[2] & 2 }
176 qw(sys$scratch /tmp /var/tmp /usr/tmp),
177 @ENV{qw(TMP TEMP)})[0]
178 or print "# can't find world-writeable directory to test PATH\n";
182 local $ENV{PATH} = $tmp;
183 test 6, eval { `$echo 1` } eq '';
184 test 7, $@ =~ /^Insecure directory in \$ENV{PATH}/, $@;
187 for (6..7) { print "ok $_ # Skipped: all directories are writeable\n" }
191 $ENV{'DCL$PATH'} = $TAINT;
192 test 8, eval { `$echo 1` } eq '';
193 test 9, $@ =~ /^Insecure \$ENV{DCL\$PATH}/, $@;
195 $ENV{'DCL$PATH'} = $tmp;
196 test 10, eval { `$echo 1` } eq '';
197 test 11, $@ =~ /^Insecure directory in \$ENV{DCL\$PATH}/, $@;
200 for (10..11) { print "ok $_ # Skipped: can't find world-writeable directory to test DCL\$PATH\n" }
202 $ENV{'DCL$PATH'} = '';
205 for (8..11) { print "ok $_ # Skipped: This is not VMS\n"; }
209 # Let's see that we can taint and untaint as needed.
212 test 12, tainted $foo;
214 # That was a sanity check. If it failed, stop the insanity!
215 die "Taint checks don't seem to be enabled" unless tainted $foo;
218 test 13, not tainted $foo;
221 test 14, tainted $foo;
224 test 15, not any_tainted @list;
225 taint_these @list[1,3,5,7,9];
226 test 16, any_tainted @list;
227 test 17, all_tainted @list[1,3,5,7,9];
228 test 18, not any_tainted @list[0,2,4,6,8];
230 ($foo) = $foo =~ /(.+)/;
231 test 19, not tainted $foo;
233 $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
234 test 20, not tainted $foo;
235 test 21, $foo eq 'bar';
240 ($foo) = ('bar' . $TAINT) =~ /(.+)/;
241 test 22, tainted $foo;
242 test 23, $foo eq 'bar';
244 $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
245 test 24, tainted $foo;
246 test 25, $foo eq 'bar';
249 $foo = $1 if 'bar' =~ /(.+)$TAINT/;
250 test 26, tainted $foo;
251 test 27, $foo eq 'bar';
253 my $pi = 4 * atan2(1,1) + $TAINT0;
254 test 28, tainted $pi;
256 ($pi) = $pi =~ /(\d+\.\d+)/;
257 test 29, not tainted $pi;
258 test 30, sprintf("%.5f", $pi) eq '3.14159';
261 # How about command-line arguments? The problem is that we don't
262 # always get some, so we'll run another process with some.
264 my $arg = catfile(curdir(), "arg$$");
265 open PROG, "> $arg" or die "Can't create $arg: $!";
267 eval { join('', @ARGV), kill 0 };
268 exit 0 if $@ =~ /^Insecure dependency/;
269 print "# Oops: \$@ was [$@]\n";
273 print `$Invoke_Perl "-T" $arg and some suspect arguments`;
274 test 31, !$?, "Exited with status $?";
278 # Reading from a file should be tainted
280 test 32, open(FILE, $TEST), "Couldn't open '$TEST': $!";
283 sysread(FILE, $block, 100);
286 test 33, tainted $block;
287 test 34, tainted $line;
290 # Globs should be forbidden, except under VMS,
291 # which doesn't spawn an external program.
292 if (1 # built-in glob
294 for (35..36) { print "ok $_\n"; }
297 my @globs = eval { <*> };
298 test 35, @globs == 0 && $@ =~ /^Insecure dependency/;
300 @globs = eval { glob '*' };
301 test 36, @globs == 0 && $@ =~ /^Insecure dependency/;
304 # Output of commands should be tainted
306 my $foo = `$echo abc`;
307 test 37, tainted $foo;
310 # Certain system variables should be tainted
312 test 38, all_tainted $^X, $0;
315 # Results of matching should all be untainted
317 my $foo = "abcdefghi" . $TAINT;
318 test 39, tainted $foo;
321 test 40, not any_tainted $`, $&, $';
323 $foo =~ /(...)(...)(...)/;
324 test 41, not any_tainted $1, $2, $3, $+;
326 my @bar = $foo =~ /(...)(...)(...)/;
327 test 42, not any_tainted @bar;
329 test 43, tainted $foo; # $foo should still be tainted!
330 test 44, $foo eq "abcdefghi";
333 # Operations which affect files can't use tainted data.
335 test 45, eval { chmod 0, $TAINT } eq '', 'chmod';
336 test 46, $@ =~ /^Insecure dependency/, $@;
338 # There is no feature test in $Config{} for truncate,
339 # so we allow for the possibility that it's missing.
340 test 47, eval { truncate 'NoSuChFiLe', $TAINT0 } eq '', 'truncate';
341 test 48, $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@;
343 test 49, eval { rename '', $TAINT } eq '', 'rename';
344 test 50, $@ =~ /^Insecure dependency/, $@;
346 test 51, eval { unlink $TAINT } eq '', 'unlink';
347 test 52, $@ =~ /^Insecure dependency/, $@;
349 test 53, eval { utime $TAINT } eq '', 'utime';
350 test 54, $@ =~ /^Insecure dependency/, $@;
352 if ($Config{d_chown}) {
353 test 55, eval { chown -1, -1, $TAINT } eq '', 'chown';
354 test 56, $@ =~ /^Insecure dependency/, $@;
357 for (55..56) { print "ok $_ # Skipped: chown() is not available\n" }
360 if ($Config{d_link}) {
361 test 57, eval { link $TAINT, '' } eq '', 'link';
362 test 58, $@ =~ /^Insecure dependency/, $@;
365 for (57..58) { print "ok $_ # Skipped: link() is not available\n" }
368 if ($Config{d_symlink}) {
369 test 59, eval { symlink $TAINT, '' } eq '', 'symlink';
370 test 60, $@ =~ /^Insecure dependency/, $@;
373 for (59..60) { print "ok $_ # Skipped: symlink() is not available\n" }
377 # Operations which affect directories can't use tainted data.
379 test 61, eval { mkdir $TAINT0, $TAINT } eq '', 'mkdir';
380 test 62, $@ =~ /^Insecure dependency/, $@;
382 test 63, eval { rmdir $TAINT } eq '', 'rmdir';
383 test 64, $@ =~ /^Insecure dependency/, $@;
385 test 65, eval { chdir $TAINT } eq '', 'chdir';
386 test 66, $@ =~ /^Insecure dependency/, $@;
388 if ($Config{d_chroot}) {
389 test 67, eval { chroot $TAINT } eq '', 'chroot';
390 test 68, $@ =~ /^Insecure dependency/, $@;
393 for (67..68) { print "ok $_ # Skipped: chroot() is not available\n" }
397 # Some operations using files can't use tainted data.
399 my $foo = "imaginary library" . $TAINT;
400 test 69, eval { require $foo } eq '', 'require';
401 test 70, $@ =~ /^Insecure dependency/, $@;
403 my $filename = "./taintB$$"; # NB: $filename isn't tainted!
404 END { unlink $filename if defined $filename }
405 $foo = $filename . $TAINT;
406 unlink $filename; # in any case
408 test 71, eval { open FOO, $foo } eq '', 'open for read';
409 test 72, $@ eq '', $@; # NB: This should be allowed
411 # Try first new style but allow also old style.
412 # We do not want the whole taint.t to fail
413 # just because Errno possibly failing.
414 test 73, eval('$!{ENOENT}') ||
415 $! == 2 || # File not found
416 ($Is_Dos && $! == 22) ||
417 ($^O eq 'mint' && $! == 33);
419 test 74, eval { open FOO, "> $foo" } eq '', 'open for write';
420 test 75, $@ =~ /^Insecure dependency/, $@;
423 # Commands to the system can't use tainted data
427 if ($^O eq 'amigaos') {
428 for (76..79) { print "ok $_ # Skipped: open('|') is not available\n" }
431 test 76, eval { open FOO, "| x$foo" } eq '', 'popen to';
432 test 77, $@ =~ /^Insecure dependency/, $@;
434 test 78, eval { open FOO, "x$foo |" } eq '', 'popen from';
435 test 79, $@ =~ /^Insecure dependency/, $@;
438 test 80, eval { exec $TAINT } eq '', 'exec';
439 test 81, $@ =~ /^Insecure dependency/, $@;
441 test 82, eval { system $TAINT } eq '', 'system';
442 test 83, $@ =~ /^Insecure dependency/, $@;
447 test 84, eval { `$echo 1$foo` } eq '', 'backticks';
448 test 85, $@ =~ /^Insecure dependency/, $@;
450 if ($Is_VMS) { # wildcard expansion doesn't invoke shell, so is safe
451 test 86, join('', eval { glob $foo } ) ne '', 'globbing';
452 test 87, $@ eq '', $@;
455 for (86..87) { print "ok $_ # Skipped: This is not VMS\n"; }
459 # Operations which affect processes can't use tainted data.
461 test 88, eval { kill 0, $TAINT } eq '', 'kill';
462 test 89, $@ =~ /^Insecure dependency/, $@;
464 if ($Config{d_setpgrp}) {
465 test 90, eval { setpgrp 0, $TAINT } eq '', 'setpgrp';
466 test 91, $@ =~ /^Insecure dependency/, $@;
469 for (90..91) { print "ok $_ # Skipped: setpgrp() is not available\n" }
472 if ($Config{d_setprior}) {
473 test 92, eval { setpriority 0, $TAINT, $TAINT } eq '', 'setpriority';
474 test 93, $@ =~ /^Insecure dependency/, $@;
477 for (92..93) { print "ok $_ # Skipped: setpriority() is not available\n" }
481 # Some miscellaneous operations can't use tainted data.
483 if ($Config{d_syscall}) {
484 test 94, eval { syscall $TAINT } eq '', 'syscall';
485 test 95, $@ =~ /^Insecure dependency/, $@;
488 for (94..95) { print "ok $_ # Skipped: syscall() is not available\n" }
495 my $temp = "./taintC$$";
497 test 96, open(FOO, "> $temp"), "Couldn't open $temp for write: $!";
499 test 97, eval { ioctl FOO, $TAINT, $foo } eq '', 'ioctl';
500 test 98, $@ =~ /^Insecure dependency/, $@;
502 if ($Config{d_fcntl}) {
503 test 99, eval { fcntl FOO, $TAINT, $foo } eq '', 'fcntl';
504 test 100, $@ =~ /^Insecure dependency/, $@;
507 for (99..100) { print "ok $_ # Skipped: fcntl() is not available\n" }
514 # Some tests involving references
516 my $foo = 'abc' . $TAINT;
518 test 101, not tainted $fooref;
519 test 102, tainted $$fooref;
520 test 103, tainted $foo;
523 # Some tests involving assignment
527 test 104, all_tainted $foo, $bar;
528 test 105, tainted($foo = $bar);
529 test 106, tainted($bar = $bar);
530 test 107, tainted($bar += $bar);
531 test 108, tainted($bar -= $bar);
532 test 109, tainted($bar *= $bar);
533 test 110, tainted($bar++);
534 test 111, tainted($bar /= $bar);
535 test 112, tainted($bar += 0);
536 test 113, tainted($bar -= 2);
537 test 114, tainted($bar *= -1);
538 test 115, tainted($bar /= 1);
539 test 116, tainted($bar--);
543 # Test assignment and return of lists
545 my @foo = ("A", "tainted" . $TAINT, "B");
546 test 118, not tainted $foo[0];
547 test 119, tainted $foo[1];
548 test 120, not tainted $foo[2];
550 test 121, not tainted $bar[0];
551 test 122, tainted $bar[1];
552 test 123, not tainted $bar[2];
553 my @baz = eval { "A", "tainted" . $TAINT, "B" };
554 test 124, not tainted $baz[0];
555 test 125, tainted $baz[1];
556 test 126, not tainted $baz[2];
557 my @plugh = eval q[ "A", "tainted" . $TAINT, "B" ];
558 test 127, not tainted $plugh[0];
559 test 128, tainted $plugh[1];
560 test 129, not tainted $plugh[2];
561 my $nautilus = sub { "A", "tainted" . $TAINT, "B" };
562 test 130, not tainted ((&$nautilus)[0]);
563 test 131, tainted ((&$nautilus)[1]);
564 test 132, not tainted ((&$nautilus)[2]);
565 my @xyzzy = &$nautilus;
566 test 133, not tainted $xyzzy[0];
567 test 134, tainted $xyzzy[1];
568 test 135, not tainted $xyzzy[2];
569 my $red_october = sub { return "A", "tainted" . $TAINT, "B" };
570 test 136, not tainted ((&$red_october)[0]);
571 test 137, tainted ((&$red_october)[1]);
572 test 138, not tainted ((&$red_october)[2]);
573 my @corge = &$red_october;
574 test 139, not tainted $corge[0];
575 test 140, tainted $corge[1];
576 test 141, not tainted $corge[2];
579 # Test for system/library calls returning string data of dubious origin.
581 # No reliable %Config check for getpw*
582 if (eval { setpwent(); getpwent() }) {
584 my @getpwent = getpwent();
585 die "getpwent: $!\n" unless (@getpwent);
586 test 142,( not tainted $getpwent[0]
587 and tainted $getpwent[1]
588 and not tainted $getpwent[2]
589 and not tainted $getpwent[3]
590 and not tainted $getpwent[4]
591 and not tainted $getpwent[5]
592 and tainted $getpwent[6] # ge?cos
593 and not tainted $getpwent[7]
594 and tainted $getpwent[8]); # shell
597 for (142) { print "ok $_ # Skipped: getpwent() is not available\n" }
600 if ($Config{d_readdir}) { # pretty hard to imagine not
602 opendir(D, "op") or die "opendir: $!\n";
603 my $readdir = readdir(D);
604 test 143, tainted $readdir;
607 for (143) { print "ok $_ # Skipped: readdir() is not available\n" }
610 if ($Config{d_readlink} && $Config{d_symlink}) {
611 my $symlink = "sl$$";
613 my $sl = "/something/naughty";
614 # it has to be a real path on Mac OS
615 $sl = MacPerl::MakePath((MacPerl::Volumes())[0]) if $Is_MacOS;
616 symlink($sl, $symlink) or die "symlink: $!\n";
617 my $readlink = readlink($symlink);
618 test 144, tainted $readlink;
621 for (144) { print "ok $_ # Skipped: readlink() or symlink() is not available\n"; }
625 # test bitwise ops (regression bug)
629 test 145, not tainted $j;
632 test 146, tainted $j;
635 # test target of substitution (regression bug)
637 my $why = $TAINT."y";
639 test 147, tainted $why;
643 test 148, tainted $why;
645 $why =~ s/e/'-'.$$/ge;
646 test 149, tainted $why;
652 print "ok 150 # skipped: no IPC::SysV\n";
655 if ($Config{'extensions'} =~ /\bIPC\/SysV\b/ && $Config{d_shm}) {
660 my $id = shmget(IPC_PRIVATE, $size, S_IRWXU);
663 if (shmwrite($id, $sent, 0, 60)) {
664 if (shmread($id, $rcvd, 0, 60)) {
665 substr($rcvd, index($rcvd, "\0")) = '';
667 warn "# shmread failed: $!\n";
670 warn "# shmwrite failed: $!\n";
672 shmctl($id, IPC_RMID, 0) or warn "# shmctl failed: $!\n";
674 warn "# shmget failed: $!\n";
677 if ($rcvd eq $sent) {
678 test 150, tainted $rcvd;
680 print "ok 150 # Skipped: SysV shared memory operation failed\n";
683 print "ok 150 # Skipped: SysV shared memory is not available\n";
690 print "ok 151 # skipped: no IPC::SysV\n";
693 if ($Config{'extensions'} =~ /\bIPC\/SysV\b/ && $Config{d_msg}) {
695 my $id = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU);
697 my $sent = "message";
698 my $type_sent = 1234;
703 if (msgsnd($id, pack("l! a*", $type_sent, $sent), IPC_NOWAIT)) {
704 if (msgrcv($id, $rcvd, 60, 0, IPC_NOWAIT)) {
705 ($type_rcvd, $rcvd) = unpack("l! a*", $rcvd);
707 warn "# msgrcv failed: $!\n";
710 warn "# msgsnd failed: $!\n";
712 msgctl($id, IPC_RMID, 0) or warn "# msgctl failed: $!\n";
714 warn "# msgget failed\n";
717 if ($rcvd eq $sent && $type_sent == $type_rcvd) {
718 test 151, tainted $rcvd;
720 print "ok 151 # Skipped: SysV message queue operation failed\n";
723 print "ok 151 # Skipped: SysV message queues are not available\n";
728 # bug id 20001004.006
730 open IN, $TEST or warn "$0: cannot read $TEST: $!" ;
734 print "not " unless tainted($a) && tainted($b) && !defined($b);
740 # bug id 20001004.007
742 open IN, $TEST or warn "$0: cannot read $TEST: $!" ;
747 print "not " unless !tainted($c->{a}) && tainted($c->{b});
752 print "not " unless tainted($d->{a}) && !tainted($d->{b});
756 b => { c => $a, d => 42 } };
757 print "not " unless !tainted($e->{a}) &&
759 tainted($e->{b}->{c}) &&
760 !tainted($e->{b}->{d});
767 # bug id 20010519.003
770 use vars qw($has_fcntl);
771 eval { require Fcntl; import Fcntl; };
777 unless ($has_fcntl) {
779 print "ok $_ # Skip: no Fcntl (no dynaloading?)\n";
782 my $evil = "foo" . $TAINT;
784 eval { sysopen(my $ro, $evil, &O_RDONLY) };
785 test 156, $@ !~ /^Insecure dependency/, $@;
787 eval { sysopen(my $wo, $evil, &O_WRONLY) };
788 test 157, $@ =~ /^Insecure dependency/, $@;
790 eval { sysopen(my $rw, $evil, &O_RDWR) };
791 test 158, $@ =~ /^Insecure dependency/, $@;
793 eval { sysopen(my $ap, $evil, &O_APPEND) };
794 test 159, $@ =~ /^Insecure dependency/, $@;
796 eval { sysopen(my $cr, $evil, &O_CREAT) };
797 test 160, $@ =~ /^Insecure dependency/, $@;
799 eval { sysopen(my $tr, $evil, &O_TRUNC) };
800 test 161, $@ =~ /^Insecure dependency/, $@;
802 eval { sysopen(my $ro, "foo", &O_RDONLY | $evil) };
803 test 162, $@ !~ /^Insecure dependency/, $@;
805 eval { sysopen(my $wo, "foo", &O_WRONLY | $evil) };
806 test 163, $@ =~ /^Insecure dependency/, $@;
808 eval { sysopen(my $rw, "foo", &O_RDWR | $evil) };
809 test 164, $@ =~ /^Insecure dependency/, $@;
811 eval { sysopen(my $ap, "foo", &O_APPEND | $evil) };
812 test 165, $@ =~ /^Insecure dependency/, $@;
814 eval { sysopen(my $cr, "foo", &O_CREAT | $evil) };
815 test 166, $@ =~ /^Insecure dependency/, $@;
817 eval { sysopen(my $tr, "foo", &O_TRUNC | $evil) };
818 test 167, $@ =~ /^Insecure dependency/, $@;
820 eval { sysopen(my $ro, "foo", &O_RDONLY, $evil) };
821 test 168, $@ !~ /^Insecure dependency/, $@;
823 eval { sysopen(my $wo, "foo", &O_WRONLY, $evil) };
824 test 169, $@ =~ /^Insecure dependency/, $@;
826 eval { sysopen(my $rw, "foo", &O_RDWR, $evil) };
827 test 170, $@ =~ /^Insecure dependency/, $@;
829 eval { sysopen(my $ap, "foo", &O_APPEND, $evil) };
830 test 171, $@ =~ /^Insecure dependency/, $@;
832 eval { sysopen(my $cr, "foo", &O_CREAT, $evil) };
833 test 172, $@ =~ /^Insecure dependency/, $@;
835 eval { sysopen(my $tr, "foo", &O_TRUNC, $evil) };
836 test 173, $@ =~ /^Insecure dependency/, $@;
838 unlink("foo"); # not unlink($evil), because that would fail...
847 local $SIG{__WARN__} = sub { print "not " };
850 my $divnum = shift()/1;
851 sprintf("%1.1f\n", $divnum);
863 # Bug ID 20010730.010
871 bless \$arg => $class;
882 my $bar = "The Big Bright Green Pleasure Machine";
884 tie my ($foo), Tie => $bar;
888 print $i == 1 ? "ok 175\n" : "not ok 175\n"
893 # Check that all environment variables are tainted.
895 while (my ($k, $v) = each %ENV) {
897 # These we have explicitly untainted or set earlier.
898 $k !~ /^(BASH_ENV|CDPATH|ENV|IFS|PATH|PERL_CORE|TEMP|TERM|TMP)$/) {
899 push @untainted, "# '$k' = '$v'\n";
902 print @untainted == 0 ? "ok 176\n" : "not ok 176\n";
903 print "# untainted:\n", @untainted if @untainted;
907 ok( ${^TAINT} == 1, '$^TAINT is on' );
909 eval { ${^TAINT} = 0 };
910 ok( ${^TAINT}, '$^TAINT is not assignable' );
911 ok( $@ =~ /^Modification of a read-only value attempted/,
912 'Assigning to ${^TAINT} fails' );
917 my $re1 = qr/x$TAINT/;
918 test 180, tainted $re1;
920 my $re2 = qr/^$re1\z/;
921 test 181, tainted $re2;
924 test 182, tainted $re3;
928 print "ok 183 # Skipped: system {} has different semantics\n";
933 local $ENV{PATH} .= $TAINT;
934 eval { system { "echo" } "/arg0", "arg1" };
935 test 183, $@ =~ /^Insecure \$ENV/;
938 for (184..205) {print "not ok $_ # TODO tainted %ENV warning occludes tainted arguments warning\n";}
942 # bug 20020208.005 plus some extras
943 # single arg exec/system are tests 80-83
944 my $err = qr/^Insecure dependency/ ;
945 test 184, eval { exec $TAINT, $TAINT } eq '', 'exec';
946 test 185, $@ =~ $err, $@;
947 test 186, eval { exec $TAINT $TAINT } eq '', 'exec';
948 test 187, $@ =~ $err, $@;
949 test 188, eval { exec $TAINT $TAINT, $TAINT } eq '', 'exec';
950 test 189, $@ =~ $err, $@;
951 test 190, eval { exec $TAINT 'notaint' } eq '', 'exec';
952 test 191, $@ =~ $err, $@;
953 test 192, eval { exec {'notaint'} $TAINT } eq '', 'exec';
954 test 193, $@ =~ $err, $@;
956 test 194, eval { system $TAINT, $TAINT } eq '', 'system';
957 test 195, $@ =~ $err, $@;
958 test 196, eval { system $TAINT $TAINT } eq '', 'system';
959 test 197, $@ =~ $err, $@;
960 test 198, eval { system $TAINT $TAINT, $TAINT } eq '', 'system';
961 test 199, $@ =~ $err, $@;
962 test 200, eval { system $TAINT 'notaint' } eq '', 'system';
963 test 201, $@ =~ $err, $@;
964 test 202, eval { system {'notaint'} $TAINT } eq '', 'system';
965 test 203, $@ =~ $err, $@;
967 eval { system("lskdfj does not exist","with","args"); };
970 print "ok 205 # no exec()\n";
972 eval { exec("lskdfj does not exist","with","args"); };
976 # If you add tests here update also the above skip block for VMS.
980 # [ID 20020704.001] taint propagation failure
983 test 206, tainted(my $foo = $1);