diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-04-29 22:53:00 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-04-29 22:53:00 +0000 |
commit | c25c5c3c87d89b68324dc98b7c8aaabc750c7cec (patch) | |
tree | 2943af9b1f84d88d863a9ba36a234877561bf5f0 /gnu/usr.bin/perl/t/op/taint.t | |
parent | 37583d269f066aa8aa04ea18126b188d12257e6d (diff) |
perl5.005_03 (stock)
Diffstat (limited to 'gnu/usr.bin/perl/t/op/taint.t')
-rw-r--r-- | gnu/usr.bin/perl/t/op/taint.t | 331 |
1 files changed, 178 insertions, 153 deletions
diff --git a/gnu/usr.bin/perl/t/op/taint.t b/gnu/usr.bin/perl/t/op/taint.t index 8437c43c453..379093f5872 100644 --- a/gnu/usr.bin/perl/t/op/taint.t +++ b/gnu/usr.bin/perl/t/op/taint.t @@ -15,8 +15,13 @@ BEGIN { use strict; use Config; +# We do not want the whole taint.t to fail +# just because Errno possibly failing. +eval { require Errno; import Errno }; + my $Is_VMS = $^O eq 'VMS'; my $Is_MSWin32 = $^O eq 'MSWin32'; +my $Is_Dos = $^O eq 'dos'; my $Invoke_Perl = $Is_VMS ? 'MCR Sys$Disk:[]Perl.' : $Is_MSWin32 ? '.\perl' : './perl'; my @MoreEnv = qw/IFS CDPATH ENV BASH_ENV/; @@ -82,7 +87,7 @@ print PROG 'print "@ARGV\n"', "\n"; close PROG; my $echo = "$Invoke_Perl $ECHO"; -print "1..140\n"; +print "1..149\n"; # First, let's make sure that Perl is checking the dangerous # environment variables. Maybe they aren't set yet, so we'll @@ -96,7 +101,7 @@ print "1..140\n"; test 1, eval { `$echo 1` } eq "1\n"; - if ($Is_MSWin32 || $Is_VMS) { + if ($Is_MSWin32 || $Is_VMS || $Is_Dos) { print "# Environment tainting tests skipped\n"; for (2..5) { print "ok $_\n" } } @@ -120,7 +125,7 @@ print "1..140\n"; } my $tmp; - if ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32) { + if ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32 || $Is_Dos) { print "# all directories are writeable\n"; } else { @@ -136,7 +141,7 @@ print "1..140\n"; test 7, $@ =~ /^Insecure directory in \$ENV{PATH}/, $@; } else { - for (6..7) { print "ok $_\n" } + for (6..7) { print "ok $_ # Skipped: all directories are writeable\n" } } if ($Is_VMS) { @@ -149,14 +154,12 @@ print "1..140\n"; test 11, $@ =~ /^Insecure directory in \$ENV{DCL\$PATH}/, $@; } else { - print "# can't find world-writeable directory to test DCL\$PATH\n"; - for (10..11) { print "ok $_\n" } + for (10..11) { print "ok $_ # Skipped: can't find world-writeable directory to test DCL\$PATH\n" } } $ENV{'DCL$PATH'} = ''; } else { - print "# This is not VMS\n"; - for (8..11) { print "ok $_\n"; } + for (8..11) { print "ok $_ # Skipped: This is not VMS\n"; } } } @@ -188,12 +191,28 @@ print "1..140\n"; 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; - test 22, tainted $pi; + test 28, tainted $pi; ($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 @@ -209,150 +228,151 @@ print "1..140\n"; }; 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'; - 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; - 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. if ($Is_VMS) { - for (29..30) { print "ok $_\n"; } + for (35..36) { print "ok $_\n"; } } else { my @globs = eval { <*> }; - test 29, @globs == 0 && $@ =~ /^Insecure dependency/; + test 35, @globs == 0 && $@ =~ /^Insecure dependency/; @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`; - test 31, tainted $foo; + test 37, tainted $foo; } # 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; - test 33, tainted $foo; + test 39, tainted $foo; $foo =~ /def/; - test 34, not any_tainted $`, $&, $'; + test 40, not any_tainted $`, $&, $'; $foo =~ /(...)(...)(...)/; - test 35, not any_tainted $1, $2, $3, $+; + test 41, not any_tainted $1, $2, $3, $+; 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. { - 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. - 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}) { - 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 { - print "# chown() is not available\n"; - for (49..50) { print "ok $_\n" } + for (55..56) { print "ok $_ # Skipped: chown() is not available\n" } } 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 { - print "# link() is not available\n"; - for (51..52) { print "ok $_\n" } + for (57..58) { print "ok $_ # Skipped: link() is not available\n" } } 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 { - print "# symlink() is not available\n"; - for (53..54) { print "ok $_\n" } + for (59..60) { print "ok $_ # Skipped: symlink() is not available\n" } } } # 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}) { - test 61, eval { chroot $TAINT } eq '', 'chroot'; - test 62, $@ =~ /^Insecure dependency/, $@; + test 67, eval { chroot $TAINT } eq '', 'chroot'; + test 68, $@ =~ /^Insecure dependency/, $@; } else { - print "# chroot() is not available\n"; - for (61..62) { print "ok $_\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; - 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 - 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. + test 73, $!{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 @@ -360,71 +380,67 @@ else { my $foo = $TAINT; if ($^O eq 'amigaos') { - print "# open(\"|\") is not available\n"; - for (70..73) { print "ok $_\n" } + for (76..79) { print "ok $_ # Skipped: open('|') is not available\n" } } else { - test 70, eval { open FOO, "| $foo" } eq '', 'popen to'; - test 71, $@ =~ /^Insecure dependency/, $@; + test 76, eval { open FOO, "| $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, "$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; - 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 - test 80, join('', eval { glob $foo } ) ne '', 'globbing'; - test 81, $@ eq '', $@; + test 86, join('', eval { glob $foo } ) ne '', 'globbing'; + test 87, $@ eq '', $@; } else { - for (80..81) { print "ok $_\n"; } + for (86..87) { print "ok $_ # Skipped: this is not VMS\n"; } } } # 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}) { - 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 { - print "# setpgrp() is not available\n"; - for (84..85) { print "ok $_\n" } + for (90..91) { print "ok $_ # Skipped: setpgrp() is not available\n" } } 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 { - print "# setpriority() is not available\n"; - for (86..87) { print "ok $_\n" } + for (92..93) { print "ok $_ # Skipped: setpriority() is not available\n" } } } # 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 { - print "# syscall() is not available\n"; - for (88..89) { print "ok $_\n" } + for (94..95) { print "ok $_ # Skipped: syscall() is not available\n" } } { @@ -433,18 +449,17 @@ else { 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}) { - 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 { - print "# fcntl() is not available\n"; - for (93..94) { print "ok $_\n" } + for (99..100) { print "ok $_ # Skipped: fcntl() is not available\n" } } close FOO; @@ -455,65 +470,65 @@ else { { 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; - 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 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; - 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" }; - 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" ]; - 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" }; - 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; - 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" }; - 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; - 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. @@ -523,7 +538,7 @@ else { setpwent(); my @getpwent = getpwent(); die "getpwent: $!\n" unless (@getpwent); - test 136,( not tainted $getpwent[0] + test 142,( not tainted $getpwent[0] and not tainted $getpwent[1] and not tainted $getpwent[2] and not tainted $getpwent[3] @@ -534,19 +549,17 @@ else { and not tainted $getpwent[8]); endpwent(); } else { - print "# getpwent() is not available\n"; - print "ok 136\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); - test 137, tainted $readdir; + test 143, tainted $readdir; closedir(OP); } else { - print "# readdir() is not available\n"; - print "ok 137\n"; + for (143) { print "ok $_ # Skipped: readdir() is not available\n" } } if ($Config{d_readlink} && $Config{d_symlink}) { @@ -554,11 +567,10 @@ else { 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 { - print "# readlink() or symlink() is not available\n"; - print "ok 138\n"; + for (144) { print "ok $_ # Skipped: readlink() or symlink() is not available\n"; } } } @@ -566,9 +578,22 @@ else { { my $why = "y"; my $j = "x" | $why; - test 139, not tainted $j; + test 145, not tainted $j; $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; +} |