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;
19 BEGIN { require './test.pl'; }
25 use vars qw($ipcsysv); # did we manage to load IPC::SysV?
28 if ($^O eq 'VMS' && !defined($Config{d_setenv})) {
29 $ENV{PATH} = $ENV{PATH};
30 $ENV{TERM} = $ENV{TERM} ne ''? $ENV{TERM} : 'dummy';
32 if ($Config{'extensions'} =~ /\bIPC\/SysV\b/
33 && ($Config{d_shm} || $Config{d_msg})) {
34 eval { require IPC::SysV };
37 IPC::SysV->import(qw(IPC_PRIVATE IPC_RMID IPC_CREAT S_IRWXU IPC_NOWAIT));
42 my $Is_MacOS = $^O eq 'MacOS';
43 my $Is_VMS = $^O eq 'VMS';
44 my $Is_MSWin32 = $^O eq 'MSWin32';
45 my $Is_NetWare = $^O eq 'NetWare';
46 my $Is_Dos = $^O eq 'dos';
47 my $Is_Cygwin = $^O eq 'cygwin';
48 my $Invoke_Perl = $Is_VMS ? 'MCR Sys$Disk:[]Perl.' :
49 $Is_MSWin32 ? '.\perl' :
51 $Is_NetWare ? 'perl' :
53 my @MoreEnv = qw/IFS CDPATH ENV BASH_ENV/;
57 for $x ('DCL$PATH', @MoreEnv) {
58 ($old{$x}) = $ENV{$x} =~ /^(.*)$/ if exists $ENV{$x};
62 \$ENV{PATH} = '' if $Config{d_setenv};
63 warn "# Note: logical name 'PATH' may have been deleted\n";
64 \@ENV{keys %old} = values %old;
70 # The empty tainted value, for tainting strings
71 my $TAINT = substr($^X, 0, 0);
72 # A tainted zero, useful for tainting numbers
79 # This taints each argument passed. All must be lvalues.
80 # Side effect: It also stringifies them. :-(
82 for (@_) { $_ .= $TAINT }
85 # How to identify taint when you see it
87 not eval { join("",@_), kill 0; 1 };
93 for (@_) { return 0 unless tainted $_ }
101 my $curr_test = curr_test();
104 print "ok $curr_test\n";
106 print "not ok $curr_test\n";
107 printf "# Failed test at line %d\n", (caller)[2];
108 for (split m/^/m, $diag) {
113 or substr($diag, -1) eq "\n";
121 # We need an external program to call.
122 my $ECHO = ($Is_MSWin32 ? ".\\echo$$" : $Is_MacOS ? ":echo$$" : ($Is_NetWare ? "echo$$" : "./echo$$"));
124 open PROG, "> $ECHO" or die "Can't create $ECHO: $!";
125 print PROG 'print "@ARGV\n"', "\n";
127 my $echo = "$Invoke_Perl $ECHO";
129 my $TEST = catfile(curdir(), 'TEST');
131 # First, let's make sure that Perl is checking the dangerous
132 # environment variables. Maybe they aren't set yet, so we'll
133 # taint them ourselves.
135 $ENV{'DCL$PATH'} = '' if $Is_VMS;
137 if ($Is_MSWin32 && $Config{ccname} =~ /bcc32/ && ! -f 'cc3250mt.dll') {
139 foreach my $dir (split /$Config{path_sep}/, $ENV{PATH}) {
140 if (-f "$dir/cc3250mt.dll") {
141 $bcc_dir = $dir and last;
144 if (defined $bcc_dir) {
146 File::Copy::copy("$bcc_dir/cc3250mt.dll", '.') or
147 die "$0: failed to copy cc3250mt.dll: $!\n";
149 END { unlink "cc3250mt.dll" }
155 delete @ENV{@MoreEnv};
158 if ($Is_Cygwin && ! -f 'cygwin1.dll') {
159 system("/usr/bin/cp /usr/bin/cygwin1.dll .") &&
160 die "$0: failed to cp cygwin1.dll: $!\n";
162 END { unlink "cygwin1.dll" }
166 if ($Is_Cygwin && ! -f 'cygcrypt-0.dll' && -f '/usr/bin/cygcrypt-0.dll') {
167 system("/usr/bin/cp /usr/bin/cygcrypt-0.dll .") &&
168 die "$0: failed to cp cygcrypt-0.dll: $!\n";
170 END { unlink "cygcrypt-0.dll" }
174 test eval { `$echo 1` } eq "1\n";
177 skip "Environment tainting tests skipped", 4
178 if $Is_MSWin32 || $Is_NetWare || $Is_VMS || $Is_Dos || $Is_MacOS;
180 my @vars = ('PATH', @MoreEnv);
181 while (my $v = $vars[0]) {
182 local $ENV{$v} = $TAINT;
183 last if eval { `$echo 1` };
184 last unless $@ =~ /^Insecure \$ENV{$v}/;
187 test !@vars, "@vars";
189 # tainted $TERM is unsafe only if it contains metachars
191 $ENV{TERM} = 'e=mc2';
192 test eval { `$echo 1` } eq "1\n";
193 $ENV{TERM} = 'e=mc2' . $TAINT;
194 test !eval { `$echo 1` };
195 test $@ =~ /^Insecure \$ENV{TERM}/, $@;
199 if ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32 || $Is_NetWare || $Is_Dos) {
200 print "# all directories are writeable\n";
203 $tmp = (grep { defined and -d and (stat _)[2] & 2 }
204 qw(sys$scratch /tmp /var/tmp /usr/tmp),
205 @ENV{qw(TMP TEMP)})[0]
206 or print "# can't find world-writeable directory to test PATH\n";
210 skip "all directories are writeable", 2 unless $tmp;
212 local $ENV{PATH} = $tmp;
213 test !eval { `$echo 1` };
214 test $@ =~ /^Insecure directory in \$ENV{PATH}/, $@;
218 skip "This is not VMS", 4 unless $Is_VMS;
220 $ENV{'DCL$PATH'} = $TAINT;
221 test eval { `$echo 1` } eq '';
222 test $@ =~ /^Insecure \$ENV{DCL\$PATH}/, $@;
224 skip q[can't find world-writeable directory to test DCL$PATH], 2
227 $ENV{'DCL$PATH'} = $tmp;
228 test eval { `$echo 1` } eq '';
229 test $@ =~ /^Insecure directory in \$ENV{DCL\$PATH}/, $@;
231 $ENV{'DCL$PATH'} = '';
235 # Let's see that we can taint and untaint as needed.
240 # That was a sanity check. If it failed, stop the insanity!
241 die "Taint checks don't seem to be enabled" unless tainted $foo;
244 test not tainted $foo;
250 test not any_tainted @list;
251 taint_these @list[1,3,5,7,9];
252 test any_tainted @list;
253 test all_tainted @list[1,3,5,7,9];
254 test not any_tainted @list[0,2,4,6,8];
256 ($foo) = $foo =~ /(.+)/;
257 test not tainted $foo;
259 $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
260 test not tainted $foo;
266 ($foo) = ('bar' . $TAINT) =~ /(.+)/;
270 $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
275 $foo = $1 if 'bar' =~ /(.+)$TAINT/;
279 my $pi = 4 * atan2(1,1) + $TAINT0;
282 ($pi) = $pi =~ /(\d+\.\d+)/;
283 test not tainted $pi;
284 test sprintf("%.5f", $pi) eq '3.14159';
287 # How about command-line arguments? The problem is that we don't
288 # always get some, so we'll run another process with some.
290 my $arg = catfile(curdir(), "arg$$");
291 open PROG, "> $arg" or die "Can't create $arg: $!";
293 eval { join('', @ARGV), kill 0 };
294 exit 0 if $@ =~ /^Insecure dependency/;
295 print "# Oops: \$@ was [$@]\n";
299 print `$Invoke_Perl "-T" $arg and some suspect arguments`;
300 test !$?, "Exited with status $?";
304 # Reading from a file should be tainted
306 test open(FILE, $TEST), "Couldn't open '$TEST': $!";
309 sysread(FILE, $block, 100);
316 # Globs should be forbidden, except under VMS,
317 # which doesn't spawn an external program.
319 skip "globs should be forbidden", 2 if 1 or $Is_VMS;
321 my @globs = eval { <*> };
322 test @globs == 0 && $@ =~ /^Insecure dependency/;
324 @globs = eval { glob '*' };
325 test @globs == 0 && $@ =~ /^Insecure dependency/;
328 # Output of commands should be tainted
330 my $foo = `$echo abc`;
334 # Certain system variables should be tainted
336 test all_tainted $^X, $0;
339 # Results of matching should all be untainted
341 my $foo = "abcdefghi" . $TAINT;
345 test not any_tainted $`, $&, $';
347 $foo =~ /(...)(...)(...)/;
348 test not any_tainted $1, $2, $3, $+;
350 my @bar = $foo =~ /(...)(...)(...)/;
351 test not any_tainted @bar;
353 test tainted $foo; # $foo should still be tainted!
354 test $foo eq "abcdefghi";
357 # Operations which affect files can't use tainted data.
359 test !eval { chmod 0, $TAINT }, 'chmod';
360 test $@ =~ /^Insecure dependency/, $@;
362 # There is no feature test in $Config{} for truncate,
363 # so we allow for the possibility that it's missing.
364 test !eval { truncate 'NoSuChFiLe', $TAINT0 }, 'truncate';
365 test $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@;
367 test !eval { rename '', $TAINT }, 'rename';
368 test $@ =~ /^Insecure dependency/, $@;
370 test !eval { unlink $TAINT }, 'unlink';
371 test $@ =~ /^Insecure dependency/, $@;
373 test !eval { utime $TAINT }, 'utime';
374 test $@ =~ /^Insecure dependency/, $@;
377 skip "chown() is not available", 2 unless $Config{d_chown};
379 test !eval { chown -1, -1, $TAINT }, 'chown';
380 test $@ =~ /^Insecure dependency/, $@;
384 skip "link() is not available", 2 unless $Config{d_link};
386 test !eval { link $TAINT, '' }, 'link';
387 test $@ =~ /^Insecure dependency/, $@;
391 skip "symlink() is not available", 2 unless $Config{d_symlink};
393 test !eval { symlink $TAINT, '' }, 'symlink';
394 test $@ =~ /^Insecure dependency/, $@;
398 # Operations which affect directories can't use tainted data.
400 test !eval { mkdir "foo".$TAINT, 0755.$TAINT0 }, 'mkdir';
401 test $@ =~ /^Insecure dependency/, $@;
403 test !eval { rmdir $TAINT }, 'rmdir';
404 test $@ =~ /^Insecure dependency/, $@;
406 test !eval { chdir "foo".$TAINT }, 'chdir';
407 test $@ =~ /^Insecure dependency/, $@;
410 skip "chroot() is not available", 2 unless $Config{d_chroot};
412 test !eval { chroot $TAINT }, 'chroot';
413 test $@ =~ /^Insecure dependency/, $@;
417 # Some operations using files can't use tainted data.
419 my $foo = "imaginary library" . $TAINT;
420 test !eval { require $foo }, 'require';
421 test $@ =~ /^Insecure dependency/, $@;
423 my $filename = "./taintB$$"; # NB: $filename isn't tainted!
424 END { unlink $filename if defined $filename }
425 $foo = $filename . $TAINT;
426 unlink $filename; # in any case
428 test !eval { open FOO, $foo }, 'open for read';
429 test $@ eq '', $@; # NB: This should be allowed
431 # Try first new style but allow also old style.
432 # We do not want the whole taint.t to fail
433 # just because Errno possibly failing.
434 test eval('$!{ENOENT}') ||
435 $! == 2 || # File not found
436 ($Is_Dos && $! == 22) ||
437 ($^O eq 'mint' && $! == 33);
439 test !eval { open FOO, "> $foo" }, 'open for write';
440 test $@ =~ /^Insecure dependency/, $@;
443 # Commands to the system can't use tainted data
448 skip "open('|') is not available", 4 if $^O eq 'amigaos';
450 test !eval { open FOO, "| x$foo" }, 'popen to';
451 test $@ =~ /^Insecure dependency/, $@;
453 test !eval { open FOO, "x$foo |" }, 'popen from';
454 test $@ =~ /^Insecure dependency/, $@;
457 test !eval { exec $TAINT }, 'exec';
458 test $@ =~ /^Insecure dependency/, $@;
460 test !eval { system $TAINT }, 'system';
461 test $@ =~ /^Insecure dependency/, $@;
466 test !eval { `$echo 1$foo` }, 'backticks';
467 test $@ =~ /^Insecure dependency/, $@;
470 # wildcard expansion doesn't invoke shell on VMS, so is safe
471 skip "This is not VMS", 2 unless $Is_VMS;
473 test join('', eval { glob $foo } ) ne '', 'globbing';
478 # Operations which affect processes can't use tainted data.
480 test !eval { kill 0, $TAINT }, 'kill';
481 test $@ =~ /^Insecure dependency/, $@;
484 skip "setpgrp() is not available", 2 unless $Config{d_setpgrp};
486 test !eval { setpgrp 0, $TAINT0 }, 'setpgrp';
487 test $@ =~ /^Insecure dependency/, $@;
491 skip "setpriority() is not available", 2 unless $Config{d_setprior};
493 test !eval { setpriority 0, $TAINT0, $TAINT0 }, 'setpriority';
494 test $@ =~ /^Insecure dependency/, $@;
498 # Some miscellaneous operations can't use tainted data.
501 skip "syscall() is not available", 2 unless $Config{d_syscall};
503 test !eval { syscall $TAINT }, 'syscall';
504 test $@ =~ /^Insecure dependency/, $@;
511 my $temp = "./taintC$$";
513 test open(FOO, "> $temp"), "Couldn't open $temp for write: $!";
515 test !eval { ioctl FOO, $TAINT0, $foo }, 'ioctl';
516 test $@ =~ /^Insecure dependency/, $@;
519 skip "fcntl() is not available", 2 unless $Config{d_fcntl};
521 test !eval { fcntl FOO, $TAINT0, $foo }, 'fcntl';
522 test $@ =~ /^Insecure dependency/, $@;
529 # Some tests involving references
531 my $foo = 'abc' . $TAINT;
533 test not tainted $fooref;
534 test tainted $$fooref;
538 # Some tests involving assignment
542 test all_tainted $foo, $bar;
543 test tainted($foo = $bar);
544 test tainted($bar = $bar);
545 test tainted($bar += $bar);
546 test tainted($bar -= $bar);
547 test tainted($bar *= $bar);
548 test tainted($bar++);
549 test tainted($bar /= $bar);
550 test tainted($bar += 0);
551 test tainted($bar -= 2);
552 test tainted($bar *= -1);
553 test tainted($bar /= 1);
554 test tainted($bar--);
558 # Test assignment and return of lists
560 my @foo = ("A", "tainted" . $TAINT, "B");
561 test not tainted $foo[0];
562 test tainted $foo[1];
563 test not tainted $foo[2];
565 test not tainted $bar[0];
566 test tainted $bar[1];
567 test not tainted $bar[2];
568 my @baz = eval { "A", "tainted" . $TAINT, "B" };
569 test not tainted $baz[0];
570 test tainted $baz[1];
571 test not tainted $baz[2];
572 my @plugh = eval q[ "A", "tainted" . $TAINT, "B" ];
573 test not tainted $plugh[0];
574 test tainted $plugh[1];
575 test not tainted $plugh[2];
576 my $nautilus = sub { "A", "tainted" . $TAINT, "B" };
577 test not tainted ((&$nautilus)[0]);
578 test tainted ((&$nautilus)[1]);
579 test not tainted ((&$nautilus)[2]);
580 my @xyzzy = &$nautilus;
581 test not tainted $xyzzy[0];
582 test tainted $xyzzy[1];
583 test not tainted $xyzzy[2];
584 my $red_october = sub { return "A", "tainted" . $TAINT, "B" };
585 test not tainted ((&$red_october)[0]);
586 test tainted ((&$red_october)[1]);
587 test not tainted ((&$red_october)[2]);
588 my @corge = &$red_october;
589 test not tainted $corge[0];
590 test tainted $corge[1];
591 test not tainted $corge[2];
594 # Test for system/library calls returning string data of dubious origin.
596 # No reliable %Config check for getpw*
598 skip "getpwent() is not available", 1 unless
599 eval { setpwent(); getpwent() };
602 my @getpwent = getpwent();
603 die "getpwent: $!\n" unless (@getpwent);
604 test ( not tainted $getpwent[0]
605 and tainted $getpwent[1]
606 and not tainted $getpwent[2]
607 and not tainted $getpwent[3]
608 and not tainted $getpwent[4]
609 and not tainted $getpwent[5]
610 and tainted $getpwent[6] # ge?cos
611 and not tainted $getpwent[7]
612 and tainted $getpwent[8]); # shell
617 # pretty hard to imagine not
618 skip "readdir() is not available", 1 unless $Config{d_readdir};
621 opendir(D, "op") or die "opendir: $!\n";
622 my $readdir = readdir(D);
623 test tainted $readdir;
628 skip "readlink() or symlink() is not available" unless
629 $Config{d_readlink} && $Config{d_symlink};
631 my $symlink = "sl$$";
633 my $sl = "/something/naughty";
634 # it has to be a real path on Mac OS
635 $sl = MacPerl::MakePath((MacPerl::Volumes())[0]) if $Is_MacOS;
636 symlink($sl, $symlink) or die "symlink: $!\n";
637 my $readlink = readlink($symlink);
638 test tainted $readlink;
643 # test bitwise ops (regression bug)
653 # test target of substitution (regression bug)
655 my $why = $TAINT."y";
663 $why =~ s/e/'-'.$$/ge;
669 skip "no IPC::SysV", 2 unless $ipcsysv;
673 skip "shm*() not available", 1 unless $Config{d_shm};
679 my $id = shmget(IPC_PRIVATE, $size, S_IRWXU);
682 if (shmwrite($id, $sent, 0, 60)) {
683 if (shmread($id, $rcvd, 0, 60)) {
684 substr($rcvd, index($rcvd, "\0")) = '';
686 warn "# shmread failed: $!\n";
689 warn "# shmwrite failed: $!\n";
691 shmctl($id, IPC_RMID, 0) or warn "# shmctl failed: $!\n";
693 warn "# shmget failed: $!\n";
696 skip "SysV shared memory operation failed", 1 unless
705 skip "msg*() not available", 1 unless $Config{d_msg};
708 my $id = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU);
710 my $sent = "message";
711 my $type_sent = 1234;
716 if (msgsnd($id, pack("l! a*", $type_sent, $sent), IPC_NOWAIT)) {
717 if (msgrcv($id, $rcvd, 60, 0, IPC_NOWAIT)) {
718 ($type_rcvd, $rcvd) = unpack("l! a*", $rcvd);
720 warn "# msgrcv failed: $!\n";
723 warn "# msgsnd failed: $!\n";
725 msgctl($id, IPC_RMID, 0) or warn "# msgctl failed: $!\n";
727 warn "# msgget failed\n";
731 skip "SysV message queue operation failed", 1
732 unless $rcvd eq $sent && $type_sent == $type_rcvd;
740 # bug id 20001004.006
742 open IN, $TEST or warn "$0: cannot read $TEST: $!" ;
747 ok tainted($a) && tainted($b) && !defined($b);
753 # bug id 20001004.007
755 open IN, $TEST or warn "$0: cannot read $TEST: $!" ;
761 ok !tainted($c->{a}) && tainted($c->{b});
766 ok tainted($d->{a}) && !tainted($d->{b});
770 b => { c => $a, d => 42 } };
771 ok !tainted($e->{a}) &&
773 tainted($e->{b}->{c}) &&
774 !tainted($e->{b}->{d});
780 # bug id 20010519.003
783 use vars qw($has_fcntl);
784 eval { require Fcntl; import Fcntl; };
791 skip "no Fcntl", 18 unless $has_fcntl;
793 my $evil = "foo" . $TAINT;
795 eval { sysopen(my $ro, $evil, &O_RDONLY) };
796 test $@ !~ /^Insecure dependency/, $@;
798 eval { sysopen(my $wo, $evil, &O_WRONLY) };
799 test $@ =~ /^Insecure dependency/, $@;
801 eval { sysopen(my $rw, $evil, &O_RDWR) };
802 test $@ =~ /^Insecure dependency/, $@;
804 eval { sysopen(my $ap, $evil, &O_APPEND) };
805 test $@ =~ /^Insecure dependency/, $@;
807 eval { sysopen(my $cr, $evil, &O_CREAT) };
808 test $@ =~ /^Insecure dependency/, $@;
810 eval { sysopen(my $tr, $evil, &O_TRUNC) };
811 test $@ =~ /^Insecure dependency/, $@;
813 eval { sysopen(my $ro, "foo", &O_RDONLY | $TAINT0) };
814 test $@ !~ /^Insecure dependency/, $@;
816 eval { sysopen(my $wo, "foo", &O_WRONLY | $TAINT0) };
817 test $@ =~ /^Insecure dependency/, $@;
819 eval { sysopen(my $rw, "foo", &O_RDWR | $TAINT0) };
820 test $@ =~ /^Insecure dependency/, $@;
822 eval { sysopen(my $ap, "foo", &O_APPEND | $TAINT0) };
823 test $@ =~ /^Insecure dependency/, $@;
825 eval { sysopen(my $cr, "foo", &O_CREAT | $TAINT0) };
826 test $@ =~ /^Insecure dependency/, $@;
828 eval { sysopen(my $tr, "foo", &O_TRUNC | $TAINT0) };
829 test $@ =~ /^Insecure dependency/, $@;
831 eval { sysopen(my $ro, "foo", &O_RDONLY, $TAINT0) };
832 test $@ !~ /^Insecure dependency/, $@;
834 eval { sysopen(my $wo, "foo", &O_WRONLY, $TAINT0) };
835 test $@ =~ /^Insecure dependency/, $@;
837 eval { sysopen(my $rw, "foo", &O_RDWR, $TAINT0) };
838 test $@ =~ /^Insecure dependency/, $@;
840 eval { sysopen(my $ap, "foo", &O_APPEND, $TAINT0) };
841 test $@ =~ /^Insecure dependency/, $@;
843 eval { sysopen(my $cr, "foo", &O_CREAT, $TAINT0) };
844 test $@ =~ /^Insecure dependency/, $@;
846 eval { sysopen(my $tr, "foo", &O_TRUNC, $TAINT0) };
847 test $@ =~ /^Insecure dependency/, $@;
849 unlink("foo"); # not unlink($evil), because that would fail...
859 local $SIG{__WARN__} = sub { $saw_warning = 1 };
862 my $divnum = shift()/1;
863 sprintf("%1.1f\n", $divnum);
875 # Bug ID 20010730.010
883 bless \$arg => $class;
894 my $bar = "The Big Bright Green Pleasure Machine";
896 tie my ($foo), Tie => $bar;
904 # Check that all environment variables are tainted.
906 while (my ($k, $v) = each %ENV) {
908 # These we have explicitly untainted or set earlier.
909 $k !~ /^(BASH_ENV|CDPATH|ENV|IFS|PATH|PERL_CORE|TEMP|TERM|TMP)$/) {
910 push @untainted, "# '$k' = '$v'\n";
913 test @untainted == 0, "untainted:\n @untainted";
917 ok( ${^TAINT} == 1, '$^TAINT is on' );
919 eval { ${^TAINT} = 0 };
920 ok( ${^TAINT}, '$^TAINT is not assignable' );
921 ok( $@ =~ /^Modification of a read-only value attempted/,
922 'Assigning to ${^TAINT} fails' );
927 my $re1 = qr/x$TAINT/;
930 my $re2 = qr/^$re1\z/;
938 skip "system {} has different semantics on Win32", 1 if $Is_MSWin32;
941 local $ENV{PATH} .= $TAINT;
942 eval { system { "echo" } "/arg0", "arg1" };
943 test $@ =~ /^Insecure \$ENV/;
947 todo_skip 'tainted %ENV warning occludes tainted arguments warning', 22
950 # bug 20020208.005 plus some single arg exec/system extras
951 my $err = qr/^Insecure dependency/ ;
952 test !eval { exec $TAINT, $TAINT }, 'exec';
954 test !eval { exec $TAINT $TAINT }, 'exec';
956 test !eval { exec $TAINT $TAINT, $TAINT }, 'exec';
958 test !eval { exec $TAINT 'notaint' }, 'exec';
960 test !eval { exec {'notaint'} $TAINT }, 'exec';
963 test !eval { system $TAINT, $TAINT }, 'system';
965 test !eval { system $TAINT $TAINT }, 'system';
967 test !eval { system $TAINT $TAINT, $TAINT }, 'system';
969 test !eval { system $TAINT 'notaint' }, 'system';
971 test !eval { system {'notaint'} $TAINT }, 'system';
976 system("lskdfj does not exist","with","args");
981 skip "no exec() on MacOS Classic" if $Is_MacOS;
985 exec("lskdfj does not exist","with","args");
990 # If you add tests here update also the above skip block for VMS.
994 # [ID 20020704.001] taint propagation failure
997 test tainted(my $foo = $1);
1001 # [perl #24291] this used to dump core
1002 our %nonmagicalenv = ( PATH => "util" );
1003 local *ENV = \%nonmagicalenv;
1004 eval { system("lskdfj"); };
1005 test $@ =~ /^%ENV is aliased to another variable while running with -T switch/;
1006 local *ENV = *nonmagicalenv;
1007 eval { system("lskdfj"); };
1008 test $@ =~ /^%ENV is aliased to %nonmagicalenv while running with -T switch/;
1015 test !tainted($notaint);
1018 $notaint =~ /($notaint)/;
1022 $notaint =~ /($TAINT)/;
1027 $TAINT =~ /($notaint)/;
1031 $TAINT =~ /($TAINT)/;
1037 ($r = $TAINT) =~ /($notaint)/;
1039 ($r = $TAINT) =~ /($TAINT)/;
1043 # accessing $^O shoudn't taint it as a side-effect;
1044 # assigning tainted data to it is now an error
1047 if (!$^X) { } elsif ($^O eq 'bar') { }
1050 test $@ =~ /Insecure dependency in/;
1053 EFFECTIVELY_CONSTANTS: {
1054 my $tainted_number = 12 + $TAINT0;
1055 test tainted( $tainted_number );
1057 # Even though it's always 0, it's still tainted
1058 my $tainted_product = $tainted_number * 0;
1059 test tainted( $tainted_product );
1060 test $tainted_product == 0;
1063 TERNARY_CONDITIONALS: {
1064 my $tainted_true = $TAINT . "blah blah blah";
1065 my $tainted_false = $TAINT0;
1066 test tainted( $tainted_true );
1067 test tainted( $tainted_false );
1069 my $result = $tainted_true ? "True" : "False";
1070 test $result eq "True";
1071 test !tainted( $result );
1073 $result = $tainted_false ? "True" : "False";
1074 test $result eq "False";
1075 test !tainted( $result );
1077 my $untainted_whatever = "The Fabulous Johnny Cash";
1078 my $tainted_whatever = "Soft Cell" . $TAINT;
1080 $result = $tainted_true ? $tainted_whatever : $untainted_whatever;
1081 test $result eq "Soft Cell";
1082 test tainted( $result );
1084 $result = $tainted_false ? $tainted_whatever : $untainted_whatever;
1085 test $result eq "The Fabulous Johnny Cash";
1086 test !tainted( $result );
1090 # rt.perl.org 5900 $1 remains tainted if...
1091 # 1) The regular expression contains a scalar variable AND
1092 # 2) The regular expression appears in an elsif clause
1094 my $foo = "abcdefghi" . $TAINT;
1096 my $valid_chars = 'a-z';
1099 elsif ( $foo =~ /([$valid_chars]+)/o ) {
1100 test not tainted $1;
1105 elsif ( my @bar = $foo =~ /([$valid_chars]+)/o ) {
1106 test not any_tainted @bar;
1110 # at scope exit, a restored localised value should have its old
1111 # taint status, not the taint status of the current statement
1118 test not tainted $x99;
1120 my $c = do { local $x99; $^X };
1121 test not tainted $x99;
1127 my $c = do { local $x99; '' };
1131 # an mg_get of a tainted value during localization shouldn't taint the
1135 eval { local $0, eval '1' };
1139 # [perl #8262] //g loops infinitely on tainted data
1145 while($a[0]=~ m/(.)/g ) {
1146 last if $i++ > 10000;
1148 test $i < 10000, "infinite m//g";