This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Taint shmread().
[perl5.git] / t / op / taint.t
CommitLineData
1e422769
PP
1#!./perl -T
2#
3# Taint tests by Tom Phoenix <rootbeer@teleport.com>.
4#
5# I don't claim to know all about tainting. If anyone sees
9607fc9c 6# tests that I've missed here, please add them. But this is
1e422769
PP
7# better than having no tests at all, right?
8#
9
10BEGIN {
11 chdir 't' if -d 't';
93430cb4 12 unshift @INC, '../lib' if -d '../lib';
1e422769
PP
13}
14
15use strict;
16use Config;
17
9d116dd7
JH
18# We do not want the whole taint.t to fail
19# just because Errno possibly failing.
20eval { require Errno; import Errno };
21
3eeba6fb
CB
22BEGIN {
23 if ($^O eq 'VMS' && !defined($Config{d_setenv})) {
24 $ENV{PATH} = $ENV{PATH};
25 $ENV{TERM} = $ENV{TERM} ne ''? $ENV{TERM} : 'dummy';
26 }
27}
28
1e422769 29my $Is_VMS = $^O eq 'VMS';
68dc0745 30my $Is_MSWin32 = $^O eq 'MSWin32';
39e571d4 31my $Is_Dos = $^O eq 'dos';
68dc0745
PP
32my $Invoke_Perl = $Is_VMS ? 'MCR Sys$Disk:[]Perl.' :
33 $Is_MSWin32 ? '.\perl' : './perl';
c90c0ff4 34my @MoreEnv = qw/IFS CDPATH ENV BASH_ENV/;
7bac28a0 35
1e422769 36if ($Is_VMS) {
7bac28a0
PP
37 my (%old, $x);
38 for $x ('DCL$PATH', @MoreEnv) {
39 ($old{$x}) = $ENV{$x} =~ /^(.*)$/ if exists $ENV{$x};
40 }
1e422769
PP
41 eval <<EndOfCleanup;
42 END {
3eeba6fb 43 \$ENV{PATH} = '' if $Config{d_setenv};
1e422769 44 warn "# Note: logical name 'PATH' may have been deleted\n";
562a7b0c 45 \@ENV{keys %old} = values %old;
1e422769
PP
46 }
47EndOfCleanup
48}
49
50# Sources of taint:
51# The empty tainted value, for tainting strings
52my $TAINT = substr($^X, 0, 0);
53# A tainted zero, useful for tainting numbers
54my $TAINT0 = 0 + $TAINT;
55
56# This taints each argument passed. All must be lvalues.
57# Side effect: It also stringifies them. :-(
58sub taint_these (@) {
59 for (@_) { $_ .= $TAINT }
60}
61
62# How to identify taint when you see it
63sub any_tainted (@) {
64 not eval { join("",@_), kill 0; 1 };
65}
66sub tainted ($) {
67 any_tainted @_;
68}
69sub all_tainted (@) {
70 for (@_) { return 0 unless tainted $_ }
71 1;
72}
73
74sub test ($$;$) {
75 my($serial, $boolean, $diag) = @_;
76 if ($boolean) {
77 print "ok $serial\n";
78 } else {
79 print "not ok $serial\n";
80 for (split m/^/m, $diag) {
81 print "# $_";
82 }
9607fc9c 83 print "\n" unless
1e422769
PP
84 $diag eq ''
85 or substr($diag, -1) eq "\n";
86 }
87}
88
89# We need an external program to call.
5aabfad6 90my $ECHO = ($Is_MSWin32 ? ".\\echo$$" : "./echo$$");
1e422769
PP
91END { unlink $ECHO }
92open PROG, "> $ECHO" or die "Can't create $ECHO: $!";
93print PROG 'print "@ARGV\n"', "\n";
94close PROG;
95my $echo = "$Invoke_Perl $ECHO";
96
d929ce6f 97print "1..150\n";
1e422769
PP
98
99# First, let's make sure that Perl is checking the dangerous
100# environment variables. Maybe they aren't set yet, so we'll
101# taint them ourselves.
102{
103 $ENV{'DCL$PATH'} = '' if $Is_VMS;
104
7bac28a0 105 $ENV{PATH} = '';
c90c0ff4 106 delete @ENV{@MoreEnv};
7bac28a0
PP
107 $ENV{TERM} = 'dumb';
108
109 test 1, eval { `$echo 1` } eq "1\n";
110
39e571d4 111 if ($Is_MSWin32 || $Is_VMS || $Is_Dos) {
7bac28a0 112 print "# Environment tainting tests skipped\n";
c90c0ff4 113 for (2..5) { print "ok $_\n" }
5aabfad6
PP
114 }
115 else {
7bac28a0
PP
116 my @vars = ('PATH', @MoreEnv);
117 while (my $v = $vars[0]) {
118 local $ENV{$v} = $TAINT;
119 last if eval { `$echo 1` };
120 last unless $@ =~ /^Insecure \$ENV{$v}/;
121 shift @vars;
122 }
123 test 2, !@vars, "\$$vars[0]";
c90c0ff4
PP
124
125 # tainted $TERM is unsafe only if it contains metachars
126 local $ENV{TERM};
127 $ENV{TERM} = 'e=mc2';
128 test 3, eval { `$echo 1` } eq "1\n";
129 $ENV{TERM} = 'e=mc2' . $TAINT;
130 test 4, eval { `$echo 1` } eq '';
131 test 5, $@ =~ /^Insecure \$ENV{TERM}/, $@;
5aabfad6 132 }
7bac28a0 133
9607fc9c 134 my $tmp;
48c036b1
GS
135 if ($^O eq 'os2' || $^O eq 'amigaos' || $Is_MSWin32 || $Is_Dos) {
136 print "# all directories are writeable\n";
137 }
138 else {
9607fc9c
PP
139 $tmp = (grep { defined and -d and (stat _)[2] & 2 }
140 qw(/tmp /var/tmp /usr/tmp /sys$scratch),
141 @ENV{qw(TMP TEMP)})[0]
142 or print "# can't find world-writeable directory to test PATH\n";
143 }
144
385588b3 145 if ($tmp) {
7bac28a0 146 local $ENV{PATH} = $tmp;
c90c0ff4
PP
147 test 6, eval { `$echo 1` } eq '';
148 test 7, $@ =~ /^Insecure directory in \$ENV{PATH}/, $@;
1e422769
PP
149 }
150 else {
fac76ed7 151 for (6..7) { print "ok $_ # Skipped: all directories are writeable\n" }
1e422769
PP
152 }
153
1e422769
PP
154 if ($Is_VMS) {
155 $ENV{'DCL$PATH'} = $TAINT;
c90c0ff4
PP
156 test 8, eval { `$echo 1` } eq '';
157 test 9, $@ =~ /^Insecure \$ENV{DCL\$PATH}/, $@;
9607fc9c
PP
158 if ($tmp) {
159 $ENV{'DCL$PATH'} = $tmp;
c90c0ff4
PP
160 test 10, eval { `$echo 1` } eq '';
161 test 11, $@ =~ /^Insecure directory in \$ENV{DCL\$PATH}/, $@;
9607fc9c
PP
162 }
163 else {
fac76ed7 164 for (10..11) { print "ok $_ # Skipped: can't find world-writeable directory to test DCL\$PATH\n" }
9607fc9c 165 }
1e422769
PP
166 $ENV{'DCL$PATH'} = '';
167 }
168 else {
fac76ed7 169 for (8..11) { print "ok $_ # Skipped: This is not VMS\n"; }
1e422769
PP
170 }
171}
172
173# Let's see that we can taint and untaint as needed.
174{
175 my $foo = $TAINT;
c90c0ff4 176 test 12, tainted $foo;
9607fc9c
PP
177
178 # That was a sanity check. If it failed, stop the insanity!
179 die "Taint checks don't seem to be enabled" unless tainted $foo;
1e422769
PP
180
181 $foo = "foo";
c90c0ff4 182 test 13, not tainted $foo;
1e422769
PP
183
184 taint_these($foo);
c90c0ff4 185 test 14, tainted $foo;
1e422769
PP
186
187 my @list = 1..10;
c90c0ff4 188 test 15, not any_tainted @list;
1e422769 189 taint_these @list[1,3,5,7,9];
c90c0ff4
PP
190 test 16, any_tainted @list;
191 test 17, all_tainted @list[1,3,5,7,9];
192 test 18, not any_tainted @list[0,2,4,6,8];
1e422769
PP
193
194 ($foo) = $foo =~ /(.+)/;
c90c0ff4 195 test 19, not tainted $foo;
1e422769
PP
196
197 $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
c90c0ff4
PP
198 test 20, not tainted $foo;
199 test 21, $foo eq 'bar';
1e422769 200
b3eb6a9b
GS
201 {
202 use re 'taint';
203
204 ($foo) = ('bar' . $TAINT) =~ /(.+)/;
205 test 22, tainted $foo;
206 test 23, $foo eq 'bar';
207
208 $foo = $1 if ('bar' . $TAINT) =~ /(.+)/;
209 test 24, tainted $foo;
210 test 25, $foo eq 'bar';
211 }
212
213 $foo = $1 if 'bar' =~ /(.+)$TAINT/;
214 test 26, tainted $foo;
215 test 27, $foo eq 'bar';
48c036b1 216
1e422769 217 my $pi = 4 * atan2(1,1) + $TAINT0;
b3eb6a9b 218 test 28, tainted $pi;
1e422769
PP
219
220 ($pi) = $pi =~ /(\d+\.\d+)/;
b3eb6a9b
GS
221 test 29, not tainted $pi;
222 test 30, sprintf("%.5f", $pi) eq '3.14159';
1e422769
PP
223}
224
225# How about command-line arguments? The problem is that we don't
226# always get some, so we'll run another process with some.
227{
228 my $arg = "./arg$$";
229 open PROG, "> $arg" or die "Can't create $arg: $!";
230 print PROG q{
231 eval { join('', @ARGV), kill 0 };
232 exit 0 if $@ =~ /^Insecure dependency/;
233 print "# Oops: \$@ was [$@]\n";
234 exit 1;
235 };
236 close PROG;
237 print `$Invoke_Perl "-T" $arg and some suspect arguments`;
b3eb6a9b 238 test 31, !$?, "Exited with status $?";
1e422769
PP
239 unlink $arg;
240}
241
242# Reading from a file should be tainted
243{
9607fc9c 244 my $file = './TEST';
b3eb6a9b 245 test 32, open(FILE, $file), "Couldn't open '$file': $!";
1e422769
PP
246
247 my $block;
248 sysread(FILE, $block, 100);
9607fc9c 249 my $line = <FILE>;
1e422769 250 close FILE;
b3eb6a9b
GS
251 test 33, tainted $block;
252 test 34, tainted $line;
1e422769
PP
253}
254
c90c0ff4
PP
255# Globs should be forbidden, except under VMS,
256# which doesn't spawn an external program.
72b16652
GS
257if (1 # built-in glob
258 or $Is_VMS) {
b3eb6a9b 259 for (35..36) { print "ok $_\n"; }
c90c0ff4
PP
260}
261else {
7bac28a0 262 my @globs = eval { <*> };
b3eb6a9b 263 test 35, @globs == 0 && $@ =~ /^Insecure dependency/;
1e422769 264
7bac28a0 265 @globs = eval { glob '*' };
b3eb6a9b 266 test 36, @globs == 0 && $@ =~ /^Insecure dependency/;
1e422769
PP
267}
268
269# Output of commands should be tainted
270{
271 my $foo = `$echo abc`;
b3eb6a9b 272 test 37, tainted $foo;
1e422769
PP
273}
274
275# Certain system variables should be tainted
276{
b3eb6a9b 277 test 38, all_tainted $^X, $0;
1e422769
PP
278}
279
280# Results of matching should all be untainted
281{
282 my $foo = "abcdefghi" . $TAINT;
b3eb6a9b 283 test 39, tainted $foo;
1e422769
PP
284
285 $foo =~ /def/;
b3eb6a9b 286 test 40, not any_tainted $`, $&, $';
1e422769
PP
287
288 $foo =~ /(...)(...)(...)/;
b3eb6a9b 289 test 41, not any_tainted $1, $2, $3, $+;
1e422769
PP
290
291 my @bar = $foo =~ /(...)(...)(...)/;
b3eb6a9b 292 test 42, not any_tainted @bar;
1e422769 293
b3eb6a9b
GS
294 test 43, tainted $foo; # $foo should still be tainted!
295 test 44, $foo eq "abcdefghi";
1e422769
PP
296}
297
298# Operations which affect files can't use tainted data.
299{
b3eb6a9b
GS
300 test 45, eval { chmod 0, $TAINT } eq '', 'chmod';
301 test 46, $@ =~ /^Insecure dependency/, $@;
1e422769 302
9607fc9c
PP
303 # There is no feature test in $Config{} for truncate,
304 # so we allow for the possibility that it's missing.
b3eb6a9b
GS
305 test 47, eval { truncate 'NoSuChFiLe', $TAINT0 } eq '', 'truncate';
306 test 48, $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@;
1e422769 307
b3eb6a9b
GS
308 test 49, eval { rename '', $TAINT } eq '', 'rename';
309 test 50, $@ =~ /^Insecure dependency/, $@;
1e422769 310
b3eb6a9b
GS
311 test 51, eval { unlink $TAINT } eq '', 'unlink';
312 test 52, $@ =~ /^Insecure dependency/, $@;
9607fc9c 313
b3eb6a9b
GS
314 test 53, eval { utime $TAINT } eq '', 'utime';
315 test 54, $@ =~ /^Insecure dependency/, $@;
48c036b1 316
1e422769 317 if ($Config{d_chown}) {
b3eb6a9b
GS
318 test 55, eval { chown -1, -1, $TAINT } eq '', 'chown';
319 test 56, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
320 }
321 else {
b3eb6a9b 322 for (55..56) { print "ok $_ # Skipped: chown() is not available\n" }
1e422769
PP
323 }
324
325 if ($Config{d_link}) {
b3eb6a9b
GS
326 test 57, eval { link $TAINT, '' } eq '', 'link';
327 test 58, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
328 }
329 else {
b3eb6a9b 330 for (57..58) { print "ok $_ # Skipped: link() is not available\n" }
1e422769
PP
331 }
332
333 if ($Config{d_symlink}) {
b3eb6a9b
GS
334 test 59, eval { symlink $TAINT, '' } eq '', 'symlink';
335 test 60, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
336 }
337 else {
b3eb6a9b 338 for (59..60) { print "ok $_ # Skipped: symlink() is not available\n" }
1e422769
PP
339 }
340}
341
342# Operations which affect directories can't use tainted data.
343{
b3eb6a9b
GS
344 test 61, eval { mkdir $TAINT0, $TAINT } eq '', 'mkdir';
345 test 62, $@ =~ /^Insecure dependency/, $@;
1e422769 346
b3eb6a9b
GS
347 test 63, eval { rmdir $TAINT } eq '', 'rmdir';
348 test 64, $@ =~ /^Insecure dependency/, $@;
9607fc9c 349
b3eb6a9b
GS
350 test 65, eval { chdir $TAINT } eq '', 'chdir';
351 test 66, $@ =~ /^Insecure dependency/, $@;
48c036b1 352
1e422769 353 if ($Config{d_chroot}) {
b3eb6a9b
GS
354 test 67, eval { chroot $TAINT } eq '', 'chroot';
355 test 68, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
356 }
357 else {
b3eb6a9b 358 for (67..68) { print "ok $_ # Skipped: chroot() is not available\n" }
1e422769
PP
359 }
360}
361
362# Some operations using files can't use tainted data.
363{
364 my $foo = "imaginary library" . $TAINT;
b3eb6a9b
GS
365 test 69, eval { require $foo } eq '', 'require';
366 test 70, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
367
368 my $filename = "./taintB$$"; # NB: $filename isn't tainted!
369 END { unlink $filename if defined $filename }
370 $foo = $filename . $TAINT;
371 unlink $filename; # in any case
372
b3eb6a9b
GS
373 test 71, eval { open FOO, $foo } eq '', 'open for read';
374 test 72, $@ eq '', $@; # NB: This should be allowed
9d116dd7
JH
375
376 # Try first new style but allow also old style.
61ae2fbf
JH
377 test 73, $!{ENOENT} ||
378 $! == 2 || # File not found
379 ($Is_Dos && $! == 22) ||
380 ($^O eq 'mint' && $! == 33);
1e422769 381
b3eb6a9b
GS
382 test 74, eval { open FOO, "> $foo" } eq '', 'open for write';
383 test 75, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
384}
385
386# Commands to the system can't use tainted data
387{
388 my $foo = $TAINT;
389
390 if ($^O eq 'amigaos') {
b3eb6a9b 391 for (76..79) { print "ok $_ # Skipped: open('|') is not available\n" }
1e422769
PP
392 }
393 else {
06eaf0bc 394 test 76, eval { open FOO, "| x$foo" } eq '', 'popen to';
b3eb6a9b 395 test 77, $@ =~ /^Insecure dependency/, $@;
1e422769 396
06eaf0bc 397 test 78, eval { open FOO, "x$foo |" } eq '', 'popen from';
b3eb6a9b 398 test 79, $@ =~ /^Insecure dependency/, $@;
48c036b1 399 }
1e422769 400
b3eb6a9b
GS
401 test 80, eval { exec $TAINT } eq '', 'exec';
402 test 81, $@ =~ /^Insecure dependency/, $@;
9607fc9c 403
b3eb6a9b
GS
404 test 82, eval { system $TAINT } eq '', 'system';
405 test 83, $@ =~ /^Insecure dependency/, $@;
48c036b1 406
1e422769
PP
407 $foo = "*";
408 taint_these $foo;
409
b3eb6a9b
GS
410 test 84, eval { `$echo 1$foo` } eq '', 'backticks';
411 test 85, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
412
413 if ($Is_VMS) { # wildcard expansion doesn't invoke shell, so is safe
b3eb6a9b
GS
414 test 86, join('', eval { glob $foo } ) ne '', 'globbing';
415 test 87, $@ eq '', $@;
1e422769
PP
416 }
417 else {
b3eb6a9b 418 for (86..87) { print "ok $_ # Skipped: this is not VMS\n"; }
1e422769
PP
419 }
420}
421
422# Operations which affect processes can't use tainted data.
423{
b3eb6a9b
GS
424 test 88, eval { kill 0, $TAINT } eq '', 'kill';
425 test 89, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
426
427 if ($Config{d_setpgrp}) {
b3eb6a9b
GS
428 test 90, eval { setpgrp 0, $TAINT } eq '', 'setpgrp';
429 test 91, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
430 }
431 else {
b3eb6a9b 432 for (90..91) { print "ok $_ # Skipped: setpgrp() is not available\n" }
1e422769
PP
433 }
434
435 if ($Config{d_setprior}) {
b3eb6a9b
GS
436 test 92, eval { setpriority 0, $TAINT, $TAINT } eq '', 'setpriority';
437 test 93, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
438 }
439 else {
b3eb6a9b 440 for (92..93) { print "ok $_ # Skipped: setpriority() is not available\n" }
1e422769
PP
441 }
442}
443
444# Some miscellaneous operations can't use tainted data.
445{
446 if ($Config{d_syscall}) {
b3eb6a9b
GS
447 test 94, eval { syscall $TAINT } eq '', 'syscall';
448 test 95, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
449 }
450 else {
b3eb6a9b 451 for (94..95) { print "ok $_ # Skipped: syscall() is not available\n" }
1e422769
PP
452 }
453
454 {
455 my $foo = "x" x 979;
456 taint_these $foo;
457 local *FOO;
458 my $temp = "./taintC$$";
459 END { unlink $temp }
b3eb6a9b 460 test 96, open(FOO, "> $temp"), "Couldn't open $temp for write: $!";
1e422769 461
b3eb6a9b
GS
462 test 97, eval { ioctl FOO, $TAINT, $foo } eq '', 'ioctl';
463 test 98, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
464
465 if ($Config{d_fcntl}) {
b3eb6a9b
GS
466 test 99, eval { fcntl FOO, $TAINT, $foo } eq '', 'fcntl';
467 test 100, $@ =~ /^Insecure dependency/, $@;
1e422769
PP
468 }
469 else {
b3eb6a9b 470 for (99..100) { print "ok $_ # Skipped: fcntl() is not available\n" }
1e422769
PP
471 }
472
473 close FOO;
474 }
475}
476
9607fc9c 477# Some tests involving references
1e422769
PP
478{
479 my $foo = 'abc' . $TAINT;
480 my $fooref = \$foo;
b3eb6a9b
GS
481 test 101, not tainted $fooref;
482 test 102, tainted $$fooref;
483 test 103, tainted $foo;
1e422769 484}
54310121
PP
485
486# Some tests involving assignment
487{
488 my $foo = $TAINT0;
489 my $bar = $foo;
b3eb6a9b
GS
490 test 104, all_tainted $foo, $bar;
491 test 105, tainted($foo = $bar);
492 test 106, tainted($bar = $bar);
493 test 107, tainted($bar += $bar);
494 test 108, tainted($bar -= $bar);
495 test 109, tainted($bar *= $bar);
496 test 110, tainted($bar++);
497 test 111, tainted($bar /= $bar);
498 test 112, tainted($bar += 0);
499 test 113, tainted($bar -= 2);
500 test 114, tainted($bar *= -1);
501 test 115, tainted($bar /= 1);
502 test 116, tainted($bar--);
503 test 117, $bar == 0;
54310121 504}
a1f49e72
CS
505
506# Test assignment and return of lists
507{
508 my @foo = ("A", "tainted" . $TAINT, "B");
b3eb6a9b
GS
509 test 118, not tainted $foo[0];
510 test 119, tainted $foo[1];
511 test 120, not tainted $foo[2];
a1f49e72 512 my @bar = @foo;
b3eb6a9b
GS
513 test 121, not tainted $bar[0];
514 test 122, tainted $bar[1];
515 test 123, not tainted $bar[2];
a1f49e72 516 my @baz = eval { "A", "tainted" . $TAINT, "B" };
b3eb6a9b
GS
517 test 124, not tainted $baz[0];
518 test 125, tainted $baz[1];
519 test 126, not tainted $baz[2];
a1f49e72 520 my @plugh = eval q[ "A", "tainted" . $TAINT, "B" ];
b3eb6a9b
GS
521 test 127, not tainted $plugh[0];
522 test 128, tainted $plugh[1];
523 test 129, not tainted $plugh[2];
a1f49e72 524 my $nautilus = sub { "A", "tainted" . $TAINT, "B" };
b3eb6a9b
GS
525 test 130, not tainted ((&$nautilus)[0]);
526 test 131, tainted ((&$nautilus)[1]);
527 test 132, not tainted ((&$nautilus)[2]);
a1f49e72 528 my @xyzzy = &$nautilus;
b3eb6a9b
GS
529 test 133, not tainted $xyzzy[0];
530 test 134, tainted $xyzzy[1];
531 test 135, not tainted $xyzzy[2];
a1f49e72 532 my $red_october = sub { return "A", "tainted" . $TAINT, "B" };
b3eb6a9b
GS
533 test 136, not tainted ((&$red_october)[0]);
534 test 137, tainted ((&$red_october)[1]);
535 test 138, not tainted ((&$red_october)[2]);
a1f49e72 536 my @corge = &$red_october;
b3eb6a9b
GS
537 test 139, not tainted $corge[0];
538 test 140, tainted $corge[1];
539 test 141, not tainted $corge[2];
a1f49e72 540}
fb73857a
PP
541
542# Test for system/library calls returning string data of dubious origin.
543{
544 # No reliable %Config check for getpw*
545 if (eval { setpwent(); getpwent(); 1 }) {
546 setpwent();
547 my @getpwent = getpwent();
548 die "getpwent: $!\n" unless (@getpwent);
b3eb6a9b 549 test 142,( not tainted $getpwent[0]
2959b6e3 550 and tainted $getpwent[1]
fb73857a
PP
551 and not tainted $getpwent[2]
552 and not tainted $getpwent[3]
553 and not tainted $getpwent[4]
554 and not tainted $getpwent[5]
3972a534 555 and tainted $getpwent[6] # ge?cos
fb73857a 556 and not tainted $getpwent[7]
3972a534 557 and tainted $getpwent[8]); # shell
fb73857a
PP
558 endpwent();
559 } else {
b3eb6a9b 560 for (142) { print "ok $_ # Skipped: getpwent() is not available\n" }
fb73857a
PP
561 }
562
563 if ($Config{d_readdir}) { # pretty hard to imagine not
564 local(*D);
565 opendir(D, "op") or die "opendir: $!\n";
566 my $readdir = readdir(D);
b3eb6a9b 567 test 143, tainted $readdir;
fb73857a
PP
568 closedir(OP);
569 } else {
b3eb6a9b 570 for (143) { print "ok $_ # Skipped: readdir() is not available\n" }
fb73857a
PP
571 }
572
573 if ($Config{d_readlink} && $Config{d_symlink}) {
574 my $symlink = "sl$$";
575 unlink($symlink);
576 symlink("/something/naughty", $symlink) or die "symlink: $!\n";
577 my $readlink = readlink($symlink);
b3eb6a9b 578 test 144, tainted $readlink;
fb73857a
PP
579 unlink($symlink);
580 } else {
b3eb6a9b 581 for (144) { print "ok $_ # Skipped: readlink() or symlink() is not available\n"; }
fb73857a
PP
582 }
583}
584
585# test bitwise ops (regression bug)
586{
587 my $why = "y";
588 my $j = "x" | $why;
b3eb6a9b 589 test 145, not tainted $j;
fb73857a
PP
590 $why = $TAINT."y";
591 $j = "x" | $why;
b3eb6a9b 592 test 146, tainted $j;
fb73857a
PP
593}
594
48c036b1
GS
595# test target of substitution (regression bug)
596{
597 my $why = $TAINT."y";
598 $why =~ s/y/z/;
b3eb6a9b 599 test 147, tainted $why;
48c036b1
GS
600
601 my $z = "[z]";
602 $why =~ s/$z/zee/;
b3eb6a9b 603 test 148, tainted $why;
48c036b1
GS
604
605 $why =~ s/e/'-'.$$/ge;
b3eb6a9b 606 test 149, tainted $why;
48c036b1 607}
d929ce6f
JH
608
609# test shmread
610{
611 if ($Config{d_shm}) {
612 use IPC::SysV qw(IPC_PRIVATE IPC_RMID S_IRWXU S_IRWXG S_IRWXO);
613
614 my $sent = "foobar";
615 my $rcvd;
616 my $size = 2000;
617 my $key = shmget(IPC_PRIVATE, $size, S_IRWXU|S_IRWXG|S_IRWXO) ||
618 warn "# shmget failed: $!\n";
619 if ($key >= 0) {
620 if (shmwrite($key, $sent, 0, 60)) {
621 if (shmread($key, $rcvd, 0, 60)) {
622 substr($rcvd, index($rcvd, "\0")) = '';
623 } else {
624 warn "# shmread failed: $!\n";
625 }
626 } else {
627 warn "# shmwrite failed: $!\n";
628 }
629 shmctl($key, IPC_RMID, 0) || warn "# shmctl failed: $!\n";
630 }
631
632 if ($rcvd eq $sent) {
633 test 150, tainted $rcvd;
634 } else {
635 print "ok 150 # Skipped: SysV shared memory operation failed\n";
636 }
637 } else {
638 for (150) { print "ok $_ # Skipped: SysV shared memory is not available\n"; }
639 }
640}