This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
VMS test and perldelta update
[perl5.git] / t / op / taint.t
index 22bb574..07b9f48 100755 (executable)
@@ -9,16 +9,53 @@
 
 BEGIN {
     chdir 't' if -d 't';
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '../lib' if -d '../lib';
+    @INC = '../lib';
 }
 
 use strict;
 use Config;
 
 }
 
 use strict;
 use Config;
 
+my $test = 177;
+sub ok ($;$) {
+    my($ok, $name) = @_;
+
+    # You have to do it this way or VMS will get confused.
+    print $ok ? "ok $test - $name\n" : "not ok $test - $name\n";
+
+    printf "# Failed test at line %d\n", (caller)[2] unless $ok;
+
+    $test++;
+    return $ok;
+}
+
+
+$| = 1;
+
+use vars qw($ipcsysv); # did we manage to load IPC::SysV?
+
+BEGIN {
+  if ($^O eq 'VMS' && !defined($Config{d_setenv})) {
+      $ENV{PATH} = $ENV{PATH};
+      $ENV{TERM} = $ENV{TERM} ne ''? $ENV{TERM} : 'dummy';
+  }
+  if ($Config{'extensions'} =~ /\bIPC\/SysV\b/
+      && ($Config{d_shm} || $Config{d_msg})) {
+      eval { require IPC::SysV };
+      unless ($@) {
+         $ipcsysv++;
+         IPC::SysV->import(qw(IPC_PRIVATE IPC_RMID IPC_CREAT S_IRWXU));
+      }
+  }
+}
+
 my $Is_VMS = $^O eq 'VMS';
 my $Is_MSWin32 = $^O eq 'MSWin32';
 my $Is_VMS = $^O eq 'VMS';
 my $Is_MSWin32 = $^O eq 'MSWin32';
+my $Is_NetWare = $^O eq 'NetWare';
+my $Is_Dos = $^O eq 'dos';
+my $Is_Cygwin = $^O eq 'cygwin';
 my $Invoke_Perl = $Is_VMS ? 'MCR Sys$Disk:[]Perl.' :
 my $Invoke_Perl = $Is_VMS ? 'MCR Sys$Disk:[]Perl.' :
-                  $Is_MSWin32 ? '.\perl' : './perl';
+                  ($Is_MSWin32 ? '.\perl' :
+                  ($Is_NetWare ? 'perl' : './perl'));
 my @MoreEnv = qw/IFS CDPATH ENV BASH_ENV/;
 
 if ($Is_VMS) {
 my @MoreEnv = qw/IFS CDPATH ENV BASH_ENV/;
 
 if ($Is_VMS) {
@@ -28,9 +65,9 @@ if ($Is_VMS) {
     }
     eval <<EndOfCleanup;
        END {
     }
     eval <<EndOfCleanup;
        END {
-           \$ENV{PATH} = '';
+           \$ENV{PATH} = '' if $Config{d_setenv};
            warn "# Note: logical name 'PATH' may have been deleted\n";
            warn "# Note: logical name 'PATH' may have been deleted\n";
-           @ENV{keys %old} = values %old;
+           \@ENV{keys %old} = values %old;
        }
 EndOfCleanup
 }
        }
 EndOfCleanup
 }
@@ -75,14 +112,14 @@ sub test ($$;$) {
 }
 
 # We need an external program to call.
 }
 
 # We need an external program to call.
-my $ECHO = ($Is_MSWin32 ? ".\\echo$$" : "./echo$$");
+my $ECHO = ($Is_MSWin32 ? ".\\echo$$" : ($Is_NetWare ? "echo$$" : "./echo$$"));
 END { unlink $ECHO }
 open PROG, "> $ECHO" or die "Can't create $ECHO: $!";
 print PROG 'print "@ARGV\n"', "\n";
 close PROG;
 my $echo = "$Invoke_Perl $ECHO";
 
 END { unlink $ECHO }
 open PROG, "> $ECHO" or die "Can't create $ECHO: $!";
 print PROG 'print "@ARGV\n"', "\n";
 close PROG;
 my $echo = "$Invoke_Perl $ECHO";
 
-print "1..140\n";
+print "1..203\n";
 
 # First, let's make sure that Perl is checking the dangerous
 # environment variables. Maybe they aren't set yet, so we'll
 
 # First, let's make sure that Perl is checking the dangerous
 # environment variables. Maybe they aren't set yet, so we'll
@@ -94,9 +131,15 @@ print "1..140\n";
     delete @ENV{@MoreEnv};
     $ENV{TERM} = 'dumb';
 
     delete @ENV{@MoreEnv};
     $ENV{TERM} = 'dumb';
 
+    if ($Is_Cygwin && ! -f 'cygwin1.dll') {
+       system("/usr/bin/cp /usr/bin/cygwin1.dll .") &&
+           die "$0: failed to cp cygwin1.dll: $!\n";
+       END { unlink "cygwin1.dll" } # yes, done for all platforms...
+    }
+
     test 1, eval { `$echo 1` } eq "1\n";
 
     test 1, eval { `$echo 1` } eq "1\n";
 
-    if ($Is_MSWin32 || $Is_VMS) {
+    if ($Is_MSWin32 || $Is_NetWare || $Is_VMS || $Is_Dos) {
        print "# Environment tainting tests skipped\n";
        for (2..5) { print "ok $_\n" }
     }
        print "# Environment tainting tests skipped\n";
        for (2..5) { print "ok $_\n" }
     }
@@ -120,9 +163,12 @@ print "1..140\n";
     }
 
     my $tmp;
     }
 
     my $tmp;
-    unless ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32) {
+    if ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32 || $Is_NetWare || $Is_Dos) {
+       print "# all directories are writeable\n";
+    }
+    else {
        $tmp = (grep { defined and -d and (stat _)[2] & 2 }
        $tmp = (grep { defined and -d and (stat _)[2] & 2 }
-                    qw(/tmp /var/tmp /usr/tmp /sys$scratch),
+                    qw(sys$scratch /tmp /var/tmp /usr/tmp),
                     @ENV{qw(TMP TEMP)})[0]
            or print "# can't find world-writeable directory to test PATH\n";
     }
                     @ENV{qw(TMP TEMP)})[0]
            or print "# can't find world-writeable directory to test PATH\n";
     }
@@ -183,12 +229,28 @@ print "1..140\n";
     test 20, not tainted $foo;
     test 21, $foo eq 'bar';
 
     test 20, not tainted $foo;
     test 21, $foo eq 'bar';
 
+    {
+      use re 'taint';
+
+      ($foo) = ('bar' . $TAINT) =~ /(.+)/;
+      test 22, tainted $foo;
+      test 23, $foo eq 'bar';
+
+      $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
+      test 24, tainted $foo;
+      test 25, $foo eq 'bar';
+    }
+
+    $foo = $1 if 'bar' =~ /(.+)$TAINT/;
+    test 26, tainted $foo;
+    test 27, $foo eq 'bar';
+
     my $pi = 4 * atan2(1,1) + $TAINT0;
     my $pi = 4 * atan2(1,1) + $TAINT0;
-    test 22, tainted $pi;
+    test 28, tainted $pi;
 
     ($pi) = $pi =~ /(\d+\.\d+)/;
 
     ($pi) = $pi =~ /(\d+\.\d+)/;
-    test 23, not tainted $pi;
-    test 24, sprintf("%.5f", $pi) eq '3.14159';
+    test 29, not tainted $pi;
+    test 30, sprintf("%.5f", $pi) eq '3.14159';
 }
 
 # How about command-line arguments? The problem is that we don't
 }
 
 # How about command-line arguments? The problem is that we don't
@@ -204,146 +266,154 @@ print "1..140\n";
     };
     close PROG;
     print `$Invoke_Perl "-T" $arg and some suspect arguments`;
     };
     close PROG;
     print `$Invoke_Perl "-T" $arg and some suspect arguments`;
-    test 25, !$?, "Exited with status $?";
+    test 31, !$?, "Exited with status $?";
     unlink $arg;
 }
 
 # Reading from a file should be tainted
 {
     my $file = './TEST';
     unlink $arg;
 }
 
 # Reading from a file should be tainted
 {
     my $file = './TEST';
-    test 26, open(FILE, $file), "Couldn't open '$file': $!";
+    test 32, open(FILE, $file), "Couldn't open '$file': $!";
 
     my $block;
     sysread(FILE, $block, 100);
     my $line = <FILE>;
     close FILE;
 
     my $block;
     sysread(FILE, $block, 100);
     my $line = <FILE>;
     close FILE;
-    test 27, tainted $block;
-    test 28, tainted $line;
+    test 33, tainted $block;
+    test 34, tainted $line;
 }
 
 # Globs should be forbidden, except under VMS,
 #   which doesn't spawn an external program.
 }
 
 # Globs should be forbidden, except under VMS,
 #   which doesn't spawn an external program.
-if ($Is_VMS) {
-    for (29..30) { print "ok $_\n"; }
+if (1  # built-in glob
+    or $Is_VMS) {
+    for (35..36) { print "ok $_\n"; }
 }
 else {
     my @globs = eval { <*> };
 }
 else {
     my @globs = eval { <*> };
-    test 29, @globs == 0 && $@ =~ /^Insecure dependency/;
+    test 35, @globs == 0 && $@ =~ /^Insecure dependency/;
 
     @globs = eval { glob '*' };
 
     @globs = eval { glob '*' };
-    test 30, @globs == 0 && $@ =~ /^Insecure dependency/;
+    test 36, @globs == 0 && $@ =~ /^Insecure dependency/;
 }
 
 # Output of commands should be tainted
 {
     my $foo = `$echo abc`;
 }
 
 # Output of commands should be tainted
 {
     my $foo = `$echo abc`;
-    test 31, tainted $foo;
+    test 37, tainted $foo;
 }
 
 # Certain system variables should be tainted
 {
 }
 
 # Certain system variables should be tainted
 {
-    test 32, all_tainted $^X, $0;
+    test 38, all_tainted $^X, $0;
 }
 
 # Results of matching should all be untainted
 {
     my $foo = "abcdefghi" . $TAINT;
 }
 
 # Results of matching should all be untainted
 {
     my $foo = "abcdefghi" . $TAINT;
-    test 33, tainted $foo;
+    test 39, tainted $foo;
 
     $foo =~ /def/;
 
     $foo =~ /def/;
-    test 34, not any_tainted $`, $&, $';
+    test 40, not any_tainted $`, $&, $';
 
     $foo =~ /(...)(...)(...)/;
 
     $foo =~ /(...)(...)(...)/;
-    test 35, not any_tainted $1, $2, $3, $+;
+    test 41, not any_tainted $1, $2, $3, $+;
 
     my @bar = $foo =~ /(...)(...)(...)/;
 
     my @bar = $foo =~ /(...)(...)(...)/;
-    test 36, not any_tainted @bar;
+    test 42, not any_tainted @bar;
 
 
-    test 37, tainted $foo;     # $foo should still be tainted!
-    test 38, $foo eq "abcdefghi";
+    test 43, tainted $foo;     # $foo should still be tainted!
+    test 44, $foo eq "abcdefghi";
 }
 
 # Operations which affect files can't use tainted data.
 {
 }
 
 # Operations which affect files can't use tainted data.
 {
-    test 39, eval { chmod 0, $TAINT } eq '', 'chmod';
-    test 40, $@ =~ /^Insecure dependency/, $@;
+    test 45, eval { chmod 0, $TAINT } eq '', 'chmod';
+    test 46, $@ =~ /^Insecure dependency/, $@;
 
     # There is no feature test in $Config{} for truncate,
     #   so we allow for the possibility that it's missing.
 
     # There is no feature test in $Config{} for truncate,
     #   so we allow for the possibility that it's missing.
-    test 41, eval { truncate 'NoSuChFiLe', $TAINT0 } eq '', 'truncate';
-    test 42, $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@;
+    test 47, eval { truncate 'NoSuChFiLe', $TAINT0 } eq '', 'truncate';
+    test 48, $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@;
 
 
-    test 43, eval { rename '', $TAINT } eq '', 'rename';
-    test 44, $@ =~ /^Insecure dependency/, $@;
+    test 49, eval { rename '', $TAINT } eq '', 'rename';
+    test 50, $@ =~ /^Insecure dependency/, $@;
 
 
-    test 45, eval { unlink $TAINT } eq '', 'unlink';
-    test 46, $@ =~ /^Insecure dependency/, $@;
+    test 51, eval { unlink $TAINT } eq '', 'unlink';
+    test 52, $@ =~ /^Insecure dependency/, $@;
 
 
-    test 47, eval { utime $TAINT } eq '', 'utime';
-    test 48, $@ =~ /^Insecure dependency/, $@;
+    test 53, eval { utime $TAINT } eq '', 'utime';
+    test 54, $@ =~ /^Insecure dependency/, $@;
 
     if ($Config{d_chown}) {
 
     if ($Config{d_chown}) {
-       test 49, eval { chown -1, -1, $TAINT } eq '', 'chown';
-       test 50, $@ =~ /^Insecure dependency/, $@;
+       test 55, eval { chown -1, -1, $TAINT } eq '', 'chown';
+       test 56, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (49..50) { print "ok $_ # Skipped: chown() is not available\n" }
+       for (55..56) { print "ok $_ # Skipped: chown() is not available\n" }
     }
 
     if ($Config{d_link}) {
     }
 
     if ($Config{d_link}) {
-       test 51, eval { link $TAINT, '' } eq '', 'link';
-       test 52, $@ =~ /^Insecure dependency/, $@;
+       test 57, eval { link $TAINT, '' } eq '', 'link';
+       test 58, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (51..52) { print "ok $_ # Skipped: link() is not available\n" }
+       for (57..58) { print "ok $_ # Skipped: link() is not available\n" }
     }
 
     if ($Config{d_symlink}) {
     }
 
     if ($Config{d_symlink}) {
-       test 53, eval { symlink $TAINT, '' } eq '', 'symlink';
-       test 54, $@ =~ /^Insecure dependency/, $@;
+       test 59, eval { symlink $TAINT, '' } eq '', 'symlink';
+       test 60, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (53..54) { print "ok $_ # Skipped: symlink() is not available\n" }
+       for (59..60) { print "ok $_ # Skipped: symlink() is not available\n" }
     }
 }
 
 # Operations which affect directories can't use tainted data.
 {
     }
 }
 
 # Operations which affect directories can't use tainted data.
 {
-    test 55, eval { mkdir $TAINT0, $TAINT } eq '', 'mkdir';
-    test 56, $@ =~ /^Insecure dependency/, $@;
+    test 61, eval { mkdir $TAINT0, $TAINT } eq '', 'mkdir';
+    test 62, $@ =~ /^Insecure dependency/, $@;
 
 
-    test 57, eval { rmdir $TAINT } eq '', 'rmdir';
-    test 58, $@ =~ /^Insecure dependency/, $@;
+    test 63, eval { rmdir $TAINT } eq '', 'rmdir';
+    test 64, $@ =~ /^Insecure dependency/, $@;
 
 
-    test 59, eval { chdir $TAINT } eq '', 'chdir';
-    test 60, $@ =~ /^Insecure dependency/, $@;
+    test 65, eval { chdir $TAINT } eq '', 'chdir';
+    test 66, $@ =~ /^Insecure dependency/, $@;
 
     if ($Config{d_chroot}) {
 
     if ($Config{d_chroot}) {
-       test 61, eval { chroot $TAINT } eq '', 'chroot';
-       test 62, $@ =~ /^Insecure dependency/, $@;
+       test 67, eval { chroot $TAINT } eq '', 'chroot';
+       test 68, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (61..62) { print "ok $_ # Skipped: chroot() is not available\n" }
+       for (67..68) { print "ok $_ # Skipped: chroot() is not available\n" }
     }
 }
 
 # Some operations using files can't use tainted data.
 {
     my $foo = "imaginary library" . $TAINT;
     }
 }
 
 # Some operations using files can't use tainted data.
 {
     my $foo = "imaginary library" . $TAINT;
-    test 63, eval { require $foo } eq '', 'require';
-    test 64, $@ =~ /^Insecure dependency/, $@;
+    test 69, eval { require $foo } eq '', 'require';
+    test 70, $@ =~ /^Insecure dependency/, $@;
 
     my $filename = "./taintB$$";       # NB: $filename isn't tainted!
     END { unlink $filename if defined $filename }
     $foo = $filename . $TAINT;
     unlink $filename;  # in any case
 
 
     my $filename = "./taintB$$";       # NB: $filename isn't tainted!
     END { unlink $filename if defined $filename }
     $foo = $filename . $TAINT;
     unlink $filename;  # in any case
 
-    test 65, eval { open FOO, $foo } eq '', 'open for read';
-    test 66, $@ eq '', $@;             # NB: This should be allowed
-    test 67, $! == 2;                  # File not found
+    test 71, eval { open FOO, $foo } eq '', 'open for read';
+    test 72, $@ eq '', $@;             # NB: This should be allowed
+
+    # Try first new style but allow also old style.
+    # We do not want the whole taint.t to fail
+    # just because Errno possibly failing.
+    test 73, eval('$!{ENOENT}') ||
+       $! == 2 || # File not found
+       ($Is_Dos && $! == 22) ||
+       ($^O eq 'mint' && $! == 33);
 
 
-    test 68, eval { open FOO, "> $foo" } eq '', 'open for write';
-    test 69, $@ =~ /^Insecure dependency/, $@;
+    test 74, eval { open FOO, "> $foo" } eq '', 'open for write';
+    test 75, $@ =~ /^Insecure dependency/, $@;
 }
 
 # Commands to the system can't use tainted data
 }
 
 # Commands to the system can't use tainted data
@@ -351,67 +421,67 @@ else {
     my $foo = $TAINT;
 
     if ($^O eq 'amigaos') {
     my $foo = $TAINT;
 
     if ($^O eq 'amigaos') {
-       for (70..73) { print "ok $_ # Skipped: open('|') is not available\n" }
+       for (76..79) { print "ok $_ # Skipped: open('|') is not available\n" }
     }
     else {
     }
     else {
-       test 70, eval { open FOO, "| $foo" } eq '', 'popen to';
-       test 71, $@ =~ /^Insecure dependency/, $@;
+       test 76, eval { open FOO, "| x$foo" } eq '', 'popen to';
+       test 77, $@ =~ /^Insecure dependency/, $@;
 
 
-       test 72, eval { open FOO, "$foo |" } eq '', 'popen from';
-       test 73, $@ =~ /^Insecure dependency/, $@;
+       test 78, eval { open FOO, "x$foo |" } eq '', 'popen from';
+       test 79, $@ =~ /^Insecure dependency/, $@;
     }
 
     }
 
-    test 74, eval { exec $TAINT } eq '', 'exec';
-    test 75, $@ =~ /^Insecure dependency/, $@;
+    test 80, eval { exec $TAINT } eq '', 'exec';
+    test 81, $@ =~ /^Insecure dependency/, $@;
 
 
-    test 76, eval { system $TAINT } eq '', 'system';
-    test 77, $@ =~ /^Insecure dependency/, $@;
+    test 82, eval { system $TAINT } eq '', 'system';
+    test 83, $@ =~ /^Insecure dependency/, $@;
 
     $foo = "*";
     taint_these $foo;
 
 
     $foo = "*";
     taint_these $foo;
 
-    test 78, eval { `$echo 1$foo` } eq '', 'backticks';
-    test 79, $@ =~ /^Insecure dependency/, $@;
+    test 84, eval { `$echo 1$foo` } eq '', 'backticks';
+    test 85, $@ =~ /^Insecure dependency/, $@;
 
     if ($Is_VMS) { # wildcard expansion doesn't invoke shell, so is safe
 
     if ($Is_VMS) { # wildcard expansion doesn't invoke shell, so is safe
-       test 80, join('', eval { glob $foo } ) ne '', 'globbing';
-       test 81, $@ eq '', $@;
+       test 86, join('', eval { glob $foo } ) ne '', 'globbing';
+       test 87, $@ eq '', $@;
     }
     else {
     }
     else {
-       for (80..81) { print "ok $_ # Skipped: this is not VMS\n"; }
+       for (86..87) { print "ok $_ # Skipped: this is not VMS\n"; }
     }
 }
 
 # Operations which affect processes can't use tainted data.
 {
     }
 }
 
 # Operations which affect processes can't use tainted data.
 {
-    test 82, eval { kill 0, $TAINT } eq '', 'kill';
-    test 83, $@ =~ /^Insecure dependency/, $@;
+    test 88, eval { kill 0, $TAINT } eq '', 'kill';
+    test 89, $@ =~ /^Insecure dependency/, $@;
 
     if ($Config{d_setpgrp}) {
 
     if ($Config{d_setpgrp}) {
-       test 84, eval { setpgrp 0, $TAINT } eq '', 'setpgrp';
-       test 85, $@ =~ /^Insecure dependency/, $@;
+       test 90, eval { setpgrp 0, $TAINT } eq '', 'setpgrp';
+       test 91, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (84..85) { print "ok $_ # Skipped: setpgrp() is not available\n" }
+       for (90..91) { print "ok $_ # Skipped: setpgrp() is not available\n" }
     }
 
     if ($Config{d_setprior}) {
     }
 
     if ($Config{d_setprior}) {
-       test 86, eval { setpriority 0, $TAINT, $TAINT } eq '', 'setpriority';
-       test 87, $@ =~ /^Insecure dependency/, $@;
+       test 92, eval { setpriority 0, $TAINT, $TAINT } eq '', 'setpriority';
+       test 93, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (86..87) { print "ok $_ # Skipped: setpriority() is not available\n" }
+       for (92..93) { print "ok $_ # Skipped: setpriority() is not available\n" }
     }
 }
 
 # Some miscellaneous operations can't use tainted data.
 {
     if ($Config{d_syscall}) {
     }
 }
 
 # Some miscellaneous operations can't use tainted data.
 {
     if ($Config{d_syscall}) {
-       test 88, eval { syscall $TAINT } eq '', 'syscall';
-       test 89, $@ =~ /^Insecure dependency/, $@;
+       test 94, eval { syscall $TAINT } eq '', 'syscall';
+       test 95, $@ =~ /^Insecure dependency/, $@;
     }
     else {
     }
     else {
-       for (88..89) { print "ok $_ # Skipped: syscall() is not available\n" }
+       for (94..95) { print "ok $_ # Skipped: syscall() is not available\n" }
     }
 
     {
     }
 
     {
@@ -420,17 +490,17 @@ else {
        local *FOO;
        my $temp = "./taintC$$";
        END { unlink $temp }
        local *FOO;
        my $temp = "./taintC$$";
        END { unlink $temp }
-       test 90, open(FOO, "> $temp"), "Couldn't open $temp for write: $!";
+       test 96, open(FOO, "> $temp"), "Couldn't open $temp for write: $!";
 
 
-       test 91, eval { ioctl FOO, $TAINT, $foo } eq '', 'ioctl';
-       test 92, $@ =~ /^Insecure dependency/, $@;
+       test 97, eval { ioctl FOO, $TAINT, $foo } eq '', 'ioctl';
+       test 98, $@ =~ /^Insecure dependency/, $@;
 
        if ($Config{d_fcntl}) {
 
        if ($Config{d_fcntl}) {
-           test 93, eval { fcntl FOO, $TAINT, $foo } eq '', 'fcntl';
-           test 94, $@ =~ /^Insecure dependency/, $@;
+           test 99, eval { fcntl FOO, $TAINT, $foo } eq '', 'fcntl';
+           test 100, $@ =~ /^Insecure dependency/, $@;
        }
        else {
        }
        else {
-           for (93..94) { print "ok $_ # Skipped: fcntl() is not available\n" }
+           for (99..100) { print "ok $_ # Skipped: fcntl() is not available\n" }
        }
 
        close FOO;
        }
 
        close FOO;
@@ -441,96 +511,96 @@ else {
 {
     my $foo = 'abc' . $TAINT;
     my $fooref = \$foo;
 {
     my $foo = 'abc' . $TAINT;
     my $fooref = \$foo;
-    test 95, not tainted $fooref;
-    test 96, tainted $$fooref;
-    test 97, tainted $foo;
+    test 101, not tainted $fooref;
+    test 102, tainted $$fooref;
+    test 103, tainted $foo;
 }
 
 # Some tests involving assignment
 {
     my $foo = $TAINT0;
     my $bar = $foo;
 }
 
 # Some tests involving assignment
 {
     my $foo = $TAINT0;
     my $bar = $foo;
-    test 98, all_tainted $foo, $bar;
-    test 99, tainted($foo = $bar);
-    test 100, tainted($bar = $bar);
-    test 101, tainted($bar += $bar);
-    test 102, tainted($bar -= $bar);
-    test 103, tainted($bar *= $bar);
-    test 104, tainted($bar++);
-    test 105, tainted($bar /= $bar);
-    test 106, tainted($bar += 0);
-    test 107, tainted($bar -= 2);
-    test 108, tainted($bar *= -1);
-    test 109, tainted($bar /= 1);
-    test 110, tainted($bar--);
-    test 111, $bar == 0;
+    test 104, all_tainted $foo, $bar;
+    test 105, tainted($foo = $bar);
+    test 106, tainted($bar = $bar);
+    test 107, tainted($bar += $bar);
+    test 108, tainted($bar -= $bar);
+    test 109, tainted($bar *= $bar);
+    test 110, tainted($bar++);
+    test 111, tainted($bar /= $bar);
+    test 112, tainted($bar += 0);
+    test 113, tainted($bar -= 2);
+    test 114, tainted($bar *= -1);
+    test 115, tainted($bar /= 1);
+    test 116, tainted($bar--);
+    test 117, $bar == 0;
 }
 
 # Test assignment and return of lists
 {
     my @foo = ("A", "tainted" . $TAINT, "B");
 }
 
 # Test assignment and return of lists
 {
     my @foo = ("A", "tainted" . $TAINT, "B");
-    test 112, not tainted $foo[0];
-    test 113,     tainted $foo[1];
-    test 114, not tainted $foo[2];
+    test 118, not tainted $foo[0];
+    test 119,     tainted $foo[1];
+    test 120, not tainted $foo[2];
     my @bar = @foo;
     my @bar = @foo;
-    test 115, not tainted $bar[0];
-    test 116,     tainted $bar[1];
-    test 117, not tainted $bar[2];
+    test 121, not tainted $bar[0];
+    test 122,     tainted $bar[1];
+    test 123, not tainted $bar[2];
     my @baz = eval { "A", "tainted" . $TAINT, "B" };
     my @baz = eval { "A", "tainted" . $TAINT, "B" };
-    test 118, not tainted $baz[0];
-    test 119,     tainted $baz[1];
-    test 120, not tainted $baz[2];
+    test 124, not tainted $baz[0];
+    test 125,     tainted $baz[1];
+    test 126, not tainted $baz[2];
     my @plugh = eval q[ "A", "tainted" . $TAINT, "B" ];
     my @plugh = eval q[ "A", "tainted" . $TAINT, "B" ];
-    test 121, not tainted $plugh[0];
-    test 122,     tainted $plugh[1];
-    test 123, not tainted $plugh[2];
+    test 127, not tainted $plugh[0];
+    test 128,     tainted $plugh[1];
+    test 129, not tainted $plugh[2];
     my $nautilus = sub { "A", "tainted" . $TAINT, "B" };
     my $nautilus = sub { "A", "tainted" . $TAINT, "B" };
-    test 124, not tainted ((&$nautilus)[0]);
-    test 125,     tainted ((&$nautilus)[1]);
-    test 126, not tainted ((&$nautilus)[2]);
+    test 130, not tainted ((&$nautilus)[0]);
+    test 131,     tainted ((&$nautilus)[1]);
+    test 132, not tainted ((&$nautilus)[2]);
     my @xyzzy = &$nautilus;
     my @xyzzy = &$nautilus;
-    test 127, not tainted $xyzzy[0];
-    test 128,     tainted $xyzzy[1];
-    test 129, not tainted $xyzzy[2];
+    test 133, not tainted $xyzzy[0];
+    test 134,     tainted $xyzzy[1];
+    test 135, not tainted $xyzzy[2];
     my $red_october = sub { return "A", "tainted" . $TAINT, "B" };
     my $red_october = sub { return "A", "tainted" . $TAINT, "B" };
-    test 130, not tainted ((&$red_october)[0]);
-    test 131,     tainted ((&$red_october)[1]);
-    test 132, not tainted ((&$red_october)[2]);
+    test 136, not tainted ((&$red_october)[0]);
+    test 137,     tainted ((&$red_october)[1]);
+    test 138, not tainted ((&$red_october)[2]);
     my @corge = &$red_october;
     my @corge = &$red_october;
-    test 133, not tainted $corge[0];
-    test 134,     tainted $corge[1];
-    test 135, not tainted $corge[2];
+    test 139, not tainted $corge[0];
+    test 140,     tainted $corge[1];
+    test 141, not tainted $corge[2];
 }
 
 # Test for system/library calls returning string data of dubious origin.
 {
     # No reliable %Config check for getpw*
 }
 
 # Test for system/library calls returning string data of dubious origin.
 {
     # No reliable %Config check for getpw*
-    if (eval { setpwent(); getpwent(); 1 }) {
+    if (eval { setpwent(); getpwent() }) {
        setpwent();
        my @getpwent = getpwent();
        die "getpwent: $!\n" unless (@getpwent);
        setpwent();
        my @getpwent = getpwent();
        die "getpwent: $!\n" unless (@getpwent);
-       test 136,(    not tainted $getpwent[0]
-                 and not tainted $getpwent[1]
+       test 142,(    not tainted $getpwent[0]
+                 and     tainted $getpwent[1]
                  and not tainted $getpwent[2]
                  and not tainted $getpwent[3]
                  and not tainted $getpwent[4]
                  and not tainted $getpwent[5]
                  and not tainted $getpwent[2]
                  and not tainted $getpwent[3]
                  and not tainted $getpwent[4]
                  and not tainted $getpwent[5]
-                 and     tainted $getpwent[6] # gecos
+                 and     tainted $getpwent[6]          # ge?cos
                  and not tainted $getpwent[7]
                  and not tainted $getpwent[7]
-                 and not tainted $getpwent[8]);
+                 and     tainted $getpwent[8]);        # shell
        endpwent();
     } else {
        endpwent();
     } else {
-       print "ok 136 # Skipped: getpwent() is not available\n";
+       for (142) { print "ok $_ # Skipped: getpwent() is not available\n" }
     }
 
     if ($Config{d_readdir}) { # pretty hard to imagine not
        local(*D);
        opendir(D, "op") or die "opendir: $!\n";
        my $readdir = readdir(D);
     }
 
     if ($Config{d_readdir}) { # pretty hard to imagine not
        local(*D);
        opendir(D, "op") or die "opendir: $!\n";
        my $readdir = readdir(D);
-       test 137, tainted $readdir;
+       test 143, tainted $readdir;
        closedir(OP);
     } else {
        closedir(OP);
     } else {
-       print "ok 137 # Skipped: readdir() is not available\n";
+       for (143) { print "ok $_ # Skipped: readdir() is not available\n" }
     }
 
     if ($Config{d_readlink} && $Config{d_symlink}) {
     }
 
     if ($Config{d_readlink} && $Config{d_symlink}) {
@@ -538,10 +608,10 @@ else {
        unlink($symlink);
        symlink("/something/naughty", $symlink) or die "symlink: $!\n";
        my $readlink = readlink($symlink);
        unlink($symlink);
        symlink("/something/naughty", $symlink) or die "symlink: $!\n";
        my $readlink = readlink($symlink);
-       test 138, tainted $readlink;
+       test 144, tainted $readlink;
        unlink($symlink);
     } else {
        unlink($symlink);
     } else {
-       print "ok 138 # Skipped: readlink() or symlink() is not available\n";
+       for (144) { print "ok $_ # Skipped: readlink() or symlink() is not available\n"; }
     }
 }
 
     }
 }
 
@@ -549,9 +619,343 @@ else {
 {
     my $why = "y";
     my $j = "x" | $why;
 {
     my $why = "y";
     my $j = "x" | $why;
-    test 139, not tainted $j;
+    test 145, not tainted $j;
     $why = $TAINT."y";
     $j = "x" | $why;
     $why = $TAINT."y";
     $j = "x" | $why;
-    test 140,     tainted $j;
+    test 146,     tainted $j;
+}
+
+# test target of substitution (regression bug)
+{
+    my $why = $TAINT."y";
+    $why =~ s/y/z/;
+    test 147,     tainted $why;
+
+    my $z = "[z]";
+    $why =~ s/$z/zee/;
+    test 148,     tainted $why;
+
+    $why =~ s/e/'-'.$$/ge;
+    test 149,     tainted $why;
+}
+
+# test shmread
+{
+    unless ($ipcsysv) {
+       print "ok 150 # skipped: no IPC::SysV\n";
+       last;
+    }
+    if ($Config{'extensions'} =~ /\bIPC\/SysV\b/ && $Config{d_shm}) {
+       no strict 'subs';
+       my $sent = "foobar";
+       my $rcvd;
+       my $size = 2000;
+       my $id = shmget(IPC_PRIVATE, $size, S_IRWXU);
+
+       if (defined $id) {
+           if (shmwrite($id, $sent, 0, 60)) {
+               if (shmread($id, $rcvd, 0, 60)) {
+                   substr($rcvd, index($rcvd, "\0")) = '';
+               } else {
+                   warn "# shmread failed: $!\n";
+               }
+           } else {
+               warn "# shmwrite failed: $!\n";
+           }
+           shmctl($id, IPC_RMID, 0) or warn "# shmctl failed: $!\n";
+       } else {
+           warn "# shmget failed: $!\n";
+       }
+
+       if ($rcvd eq $sent) {
+           test 150, tainted $rcvd;
+       } else {
+           print "ok 150 # Skipped: SysV shared memory operation failed\n";
+       }
+    } else {
+       print "ok 150 # Skipped: SysV shared memory is not available\n";
+    }
+}
+
+# test msgrcv
+{
+    unless ($ipcsysv) {
+       print "ok 151 # skipped: no IPC::SysV\n";
+       last;
+    }
+    if ($Config{'extensions'} =~ /\bIPC\/SysV\b/ && $Config{d_msg}) {
+       no strict 'subs';
+       my $id = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU);
+
+       my $sent      = "message";
+       my $type_sent = 1234;
+       my $rcvd;
+       my $type_rcvd;
+
+       if (defined $id) {
+           if (msgsnd($id, pack("l! a*", $type_sent, $sent), 0)) {
+               if (msgrcv($id, $rcvd, 60, 0, 0)) {
+                   ($type_rcvd, $rcvd) = unpack("l! a*", $rcvd);
+               } else {
+                   warn "# msgrcv failed\n";
+               }
+           } else {
+               warn "# msgsnd failed\n";
+           }
+           msgctl($id, IPC_RMID, 0) or warn "# msgctl failed: $!\n";
+       } else {
+           warn "# msgget failed\n";
+       }
+
+       if ($rcvd eq $sent && $type_sent == $type_rcvd) {
+           test 151, tainted $rcvd;
+       } else {
+           print "ok 151 # Skipped: SysV message queue operation failed\n";
+       }
+    } else {
+       print "ok 151 # Skipped: SysV message queues are not available\n";
+    }
 }
 
 }
 
+{
+    # bug id 20001004.006
+
+    open IN, "./TEST" or warn "$0: cannot read ./TEST: $!" ;
+    local $/;
+    my $a = <IN>;
+    my $b = <IN>;
+    print "not " unless tainted($a) && tainted($b) && !defined($b);
+    print "ok 152\n";
+    close IN;
+}
+
+{
+    # bug id 20001004.007
+
+    open IN, "./TEST" or warn "$0: cannot read ./TEST: $!" ;
+    my $a = <IN>;
+
+    my $c = { a => 42,
+             b => $a };
+    print "not " unless !tainted($c->{a}) && tainted($c->{b});
+    print "ok 153\n";
+
+    my $d = { a => $a,
+             b => 42 };
+    print "not " unless tainted($d->{a}) && !tainted($d->{b});
+    print "ok 154\n";
+
+    my $e = { a => 42,
+             b => { c => $a, d => 42 } };
+    print "not " unless !tainted($e->{a}) &&
+                       !tainted($e->{b}) &&
+                        tainted($e->{b}->{c}) &&
+                       !tainted($e->{b}->{d});
+    print "ok 155\n";
+
+    close IN;
+}
+
+{
+    # bug id 20010519.003
+
+    BEGIN {
+       use vars qw($has_fcntl);
+       eval { require Fcntl; import Fcntl; };
+       unless ($@) {
+           $has_fcntl = 1;
+       }
+    }
+
+    unless ($has_fcntl) {
+       for (156..173) {
+           print "ok $_ # Skip: no Fcntl (no dynaloading?)\n";
+       }
+    } else {
+       my $evil = "foo" . $TAINT;
+
+       eval { sysopen(my $ro, $evil, &O_RDONLY) };
+       test 156, $@ !~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $wo, $evil, &O_WRONLY) };
+       test 157, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $rw, $evil, &O_RDWR) };
+       test 158, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $ap, $evil, &O_APPEND) };
+       test 159, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $cr, $evil, &O_CREAT) };
+       test 160, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $tr, $evil, &O_TRUNC) };
+       test 161, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $ro, "foo", &O_RDONLY | $evil) };
+       test 162, $@ !~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $wo, "foo", &O_WRONLY | $evil) };
+       test 163, $@ =~ /^Insecure dependency/, $@;
+
+       eval { sysopen(my $rw, "foo", &O_RDWR | $evil) };
+       test 164, $@ =~ /^Insecure dependency/, $@;
+
+       eval { sysopen(my $ap, "foo", &O_APPEND | $evil) };
+       test 165, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $cr, "foo", &O_CREAT | $evil) };
+       test 166, $@ =~ /^Insecure dependency/, $@;
+
+       eval { sysopen(my $tr, "foo", &O_TRUNC | $evil) };
+       test 167, $@ =~ /^Insecure dependency/, $@;
+
+       eval { sysopen(my $ro, "foo", &O_RDONLY, $evil) };
+       test 168, $@ !~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $wo, "foo", &O_WRONLY, $evil) };
+       test 169, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $rw, "foo", &O_RDWR, $evil) };
+       test 170, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $ap, "foo", &O_APPEND, $evil) };
+       test 171, $@ =~ /^Insecure dependency/, $@;
+       
+       eval { sysopen(my $cr, "foo", &O_CREAT, $evil) };
+       test 172, $@ =~ /^Insecure dependency/, $@;
+
+       eval { sysopen(my $tr, "foo", &O_TRUNC, $evil) };
+       test 173, $@ =~ /^Insecure dependency/, $@;
+       
+       unlink("foo"); # not unlink($evil), because that would fail...
+    }
+}
+
+{
+    # bug 20010526.004
+
+    use warnings;
+
+    local $SIG{__WARN__} = sub { print "not " };
+
+    sub fmi {
+       my $divnum = shift()/1;
+       sprintf("%1.1f\n", $divnum);
+    }
+
+    fmi(21 . $TAINT);
+    fmi(37);
+    fmi(248);
+
+    print "ok 174\n";
+}
+
+
+{
+    # Bug ID 20010730.010
+
+    my $i = 0;
+
+    sub Tie::TIESCALAR {
+        my $class =  shift;
+        my $arg   =  shift;
+
+        bless \$arg => $class;
+    }
+
+    sub Tie::FETCH {
+        $i ++;
+        ${$_ [0]}
+    }
+
+    package main;
+    my $bar = "The Big Bright Green Pleasure Machine";
+    taint_these $bar;
+    tie my ($foo), Tie => $bar;
+
+    my $baz = $foo;
+
+    print $i == 1 ? "ok 175\n" : "not ok 175\n"
+
+}
+
+{
+    # Check that all environment variables are tainted.
+    my @untainted;
+    while (my ($k, $v) = each %ENV) {
+       if (!tainted($v) &&
+           # These we have untainted explicitly earlier.
+           $k !~ /^(BASH_ENV|CDPATH|ENV|IFS|PATH|TEMP|TERM|TMP)$/) {
+           push @untainted, "# '$k' = '$v'\n";
+       }
+    }
+    print @untainted == 0 ? "ok 176\n" : "not ok 176\n";
+    print "# untainted:\n", @untainted if @untainted; 
+}
+
+
+ok( ${^TAINT},  '$^TAINT is on' );
+
+eval { ${^TAINT} = 0 };
+ok( ${^TAINT},  '$^TAINT is not assignable' );
+ok( $@ =~ /^Modification of a read-only value attempted/,
+                                'Assigning to ${^TAINT} fails' );
+
+{
+    # bug 20011111.105
+    
+    my $re1 = qr/x$TAINT/;
+    test 180, tainted $re1;
+    
+    my $re2 = qr/^$re1\z/;
+    test 181, tainted $re2;
+    
+    my $re3 = "$re2";
+    test 182, tainted $re3;
+}
+
+if ($Is_MSWin32) {
+    print "ok 183 # Skipped: system {} has different semantics\n"; 
+}
+else
+{
+    # bug 20010221.005
+    local $ENV{PATH} .= $TAINT;
+    eval { system { "echo" } "/arg0", "arg1" };
+    test 183, $@ =~ /^Insecure \$ENV/;
+}
+if ($Is_VMS) {
+    for (184..203) {print "not ok $_ # TODO tainted %ENV warning occludes tainted arguments warning\n";}
+}
+else 
+{
+    # bug 20020208.005 plus some extras
+    # single arg exec/system are tests 80-83
+    use if $] lt '5.009', warnings => FATAL => 'taint';
+    my $err = $] ge '5.009' ? qr/^Insecure dependency/ 
+                            : qr/^Use of tainted arguments/;
+    test 184, eval { exec $TAINT, $TAINT } eq '', 'exec';
+    test 185, $@ =~ $err, $@;
+    test 186, eval { exec $TAINT $TAINT } eq '', 'exec';
+    test 187, $@ =~ $err, $@;
+    test 188, eval { exec $TAINT $TAINT, $TAINT } eq '', 'exec';
+    test 189, $@ =~ $err, $@;
+    test 190, eval { exec $TAINT 'notaint' } eq '', 'exec';
+    test 191, $@ =~ $err, $@;
+    test 192, eval { exec {'notaint'} $TAINT } eq '', 'exec';
+    test 193, $@ =~ $err, $@;
+
+    test 194, eval { system $TAINT, $TAINT } eq '', 'system';
+    test 195, $@ =~ $err, $@;
+    test 196, eval { system $TAINT $TAINT } eq '', 'exec';
+    test 197, $@ =~ $err, $@;
+    test 198, eval { system $TAINT $TAINT, $TAINT } eq '', 'exec';
+    test 199, $@ =~ $err, $@;
+    test 200, eval { system $TAINT 'notaint' } eq '', 'exec';
+    test 201, $@ =~ $err, $@;
+    test 202, eval { system {'notaint'} $TAINT } eq '', 'exec';
+    test 203, $@ =~ $err, $@;
+}