summaryrefslogtreecommitdiff
path: root/ext/POSIX/t
diff options
context:
space:
mode:
authorPaul Marquess <paul.marquess@btinternet.com>2002-06-19 10:29:22 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2002-06-19 12:20:54 +0000
commit0e247040c68e14832dcdbb2508a8f1cc78bc5480 (patch)
tree12f00035f2c7c44f70d94c3aacef6c24896ec62c /ext/POSIX/t
parent6ebe41ac4b371ed6f440022cad1f0a13ea938e37 (diff)
downloadperl-0e247040c68e14832dcdbb2508a8f1cc78bc5480.tar.gz
POSIX taint tests
From: "Paul Marquess" <Paul.Marquess@btinternet.com> Message-ID: <AIEAJICLCBDNAAOLLOKLMEFJEOAA.Paul.Marquess@btinternet.com> p4raw-id: //depot/perl@17296
Diffstat (limited to 'ext/POSIX/t')
-rw-r--r--ext/POSIX/t/taint.t47
1 files changed, 47 insertions, 0 deletions
diff --git a/ext/POSIX/t/taint.t b/ext/POSIX/t/taint.t
new file mode 100644
index 0000000000..2fc171b182
--- /dev/null
+++ b/ext/POSIX/t/taint.t
@@ -0,0 +1,47 @@
+#!./perl -Tw
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require Config; import Config;
+ if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
+ print "1..0\n";
+ exit 0;
+ }
+}
+
+require "./test.pl";
+use Scalar::Util qw/tainted/;
+plan(tests => 5);
+
+
+use POSIX qw(fcntl_h open read mkfifo);
+use strict ;
+
+$| = 1;
+
+my $buffer;
+my @buffer;
+my $testfd;
+
+# Sources of taint:
+# The empty tainted value, for tainting strings
+
+my $TAINT = substr($^X, 0, 0);
+
+eval { mkfifo($TAINT. "TEST", 0) };
+ok($@ =~ /^Insecure dependency/, 'mkfifo with tainted data');
+
+eval { $testfd = open($TAINT. "TEST", O_WRONLY, 0) };
+ok($@ =~ /^Insecure dependency/, 'open with tainted data');
+
+eval { $testfd = open("TEST", O_RDONLY, 0) };
+ok($@ eq "", 'open with untainted data');
+
+read($testfd, $buffer, 2) if $testfd > 2;
+is( $buffer, "#!", ' read' );
+ok(tainted($buffer), ' scalar tainted');
+read($testfd, $buffer[1], 2) if $testfd > 2;
+
+#is( $buffer[1], "./", ' read' );
+#ok(tainted($buffer[1]), ' array element tainted');