From: Gurusamy Sarathy Date: Sat, 4 Jul 1998 01:51:47 +0000 (+0000) Subject: merge changes#1210,1211,1270 from maintbranch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b3eb6a9ba72c92b7decf330d8d63b32ba5499629;p=p5sagit%2Fp5-mst-13.2.git merge changes#1210,1211,1270 from maintbranch p4raw-link: @1270 on //depot/maint-5.004/perl: 413603941653f55130af336b8e990052b26673a6 p4raw-link: @1211 on //depot/maint-5.004/perl: 247620c138019426962998dd7edc0157874220f0 p4raw-link: @1210 on //depot/maint-5.004/perl: 4522f71f5c16bf8892b1952004accec53aab868e p4raw-id: //depot/perl@1277 --- diff --git a/MANIFEST b/MANIFEST index 6dd7c59..9c2eddd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -558,6 +558,7 @@ lib/open3.pl Open a three-ended pipe (uses IPC::Open3) lib/overload.pm Module for overloading perl operators lib/perl5db.pl Perl debugging routines lib/pwd.pl Routines to keep track of PWD environment variable +lib/re.pm Pragmas for regular expressions lib/shellwords.pl Perl library to split into words with shell quoting lib/sigtrap.pm For trapping an abort and giving traceback lib/stat.pl Perl library supporting stat function diff --git a/dump.c b/dump.c index b34b5d4..8735585 100644 --- a/dump.c +++ b/dump.c @@ -369,6 +369,8 @@ dump_pm(PMOP *pm) SV *tmpsv = newSVpv("", 0); if (pm->op_pmdynflags & PMdf_USED) sv_catpv(tmpsv, ",USED"); + if (pm->op_pmdynflags & PMdf_TAINTED) + sv_catpv(tmpsv, ",TAINTED"); if (pm->op_pmflags & PMf_ONCE) sv_catpv(tmpsv, ",ONCE"); if (pm->op_pmregexp && pm->op_pmregexp->check_substr @@ -387,8 +389,8 @@ dump_pm(PMOP *pm) sv_catpv(tmpsv, ",GLOBAL"); if (pm->op_pmflags & PMf_CONTINUE) sv_catpv(tmpsv, ",CONTINUE"); - if (pm->op_pmflags & PMf_TAINTMEM) - sv_catpv(tmpsv, ",TAINTMEM"); + if (pm->op_pmflags & PMf_RETAINT) + sv_catpv(tmpsv, ",RETAINT"); if (pm->op_pmflags & PMf_EVAL) sv_catpv(tmpsv, ",EVAL"); dump("PMFLAGS = (%s)\n", SvCUR(tmpsv) ? SvPVX(tmpsv) + 1 : ""); diff --git a/installperl b/installperl index 0769c03..dadb99b 100755 --- a/installperl +++ b/installperl @@ -52,7 +52,6 @@ if ($scr_ext) { @scripts = map { "$_$scr_ext" } @scripts; } %archpms = ( Config => 1, FileHandle => 1, overload => 1, - 'File/Basename' => 1, # uses m//t ); if ($^O eq 'dos') { diff --git a/lib/File/Basename.pm b/lib/File/Basename.pm index e21af92..69bb1fa 100644 --- a/lib/File/Basename.pm +++ b/lib/File/Basename.pm @@ -122,11 +122,13 @@ directory name to be F<.>). =cut -require 5.002; + +## use strict; +use re 'taint'; + require Exporter; @ISA = qw(Exporter); @EXPORT = qw(fileparse fileparse_set_fstype basename dirname); -#use strict; use vars qw($VERSION $Fileparse_fstype $Fileparse_igncase); $VERSION = "2.6"; @@ -160,23 +162,23 @@ sub fileparse { if ($fstype =~ /^VMS/i) { if ($fullname =~ m#/#) { $fstype = '' } # We're doing Unix emulation else { - ($dirpath,$basename) = ($fullname =~ /^(.*[:>\]])?(.*)/t); + ($dirpath,$basename) = ($fullname =~ /^(.*[:>\]])?(.*)/); $dirpath ||= ''; # should always be defined } } if ($fstype =~ /^MS(DOS|Win32)/i) { - ($dirpath,$basename) = ($fullname =~ /^((?:.*[:\\\/])?)(.*)/t); + ($dirpath,$basename) = ($fullname =~ /^((?:.*[:\\\/])?)(.*)/); $dirpath .= '.\\' unless $dirpath =~ /[\\\/]$/; } elsif ($fstype =~ /^MacOS/i) { - ($dirpath,$basename) = ($fullname =~ /^(.*:)?(.*)/t); + ($dirpath,$basename) = ($fullname =~ /^(.*:)?(.*)/); } elsif ($fstype =~ /^AmigaOS/i) { - ($dirpath,$basename) = ($fullname =~ /(.*[:\/])?(.*)/t); + ($dirpath,$basename) = ($fullname =~ /(.*[:\/])?(.*)/); $dirpath = './' unless $dirpath; } elsif ($fstype !~ /^VMS/i) { # default to Unix - ($dirpath,$basename) = ($fullname =~ m#^(.*/)?(.*)#t); + ($dirpath,$basename) = ($fullname =~ m#^(.*/)?(.*)#); if ($^O eq 'VMS' and $fullname =~ m:/[^/]+/000000/?:) { # dev:[000000] is top of VMS tree, similar to Unix '/' ($basename,$dirpath) = ('',$fullname); @@ -188,7 +190,7 @@ sub fileparse { $tail = ''; foreach $suffix (@suffices) { my $pat = ($igncase ? '(?i)' : '') . "($suffix)\$"; - if ($basename =~ s/$pat//t) { + if ($basename =~ s/$pat//) { $taint .= substr($suffix,0,0); $tail = $1 . $tail; } @@ -226,30 +228,30 @@ sub dirname { } if ($fstype =~ /MacOS/i) { return $dirname } elsif ($fstype =~ /MSDOS/i) { - $dirname =~ s/([^:])[\\\/]*$/$1/t; + $dirname =~ s/([^:])[\\\/]*$/$1/; unless( length($basename) ) { ($basename,$dirname) = fileparse $dirname; - $dirname =~ s/([^:])[\\\/]*$/$1/t; + $dirname =~ s/([^:])[\\\/]*$/$1/; } } elsif ($fstype =~ /MSWin32/i) { - $dirname =~ s/([^:])[\\\/]*$/$1/t; + $dirname =~ s/([^:])[\\\/]*$/$1/; unless( length($basename) ) { ($basename,$dirname) = fileparse $dirname; - $dirname =~ s/([^:])[\\\/]*$/$1/t; + $dirname =~ s/([^:])[\\\/]*$/$1/; } } elsif ($fstype =~ /AmigaOS/i) { if ( $dirname =~ /:$/) { return $dirname } chop $dirname; - $dirname =~ s#[^:/]+$##t unless length($basename); + $dirname =~ s#[^:/]+$## unless length($basename); } else { $dirname =~ s:(.)/*$:$1:; unless( length($basename) ) { local($File::Basename::Fileparse_fstype) = $fstype; ($basename,$dirname) = fileparse $dirname; - $dirname =~ s:(.)/*$:$1:t; + $dirname =~ s:(.)/*$:$1:; } } diff --git a/lib/re.pm b/lib/re.pm new file mode 100644 index 0000000..07626c2 --- /dev/null +++ b/lib/re.pm @@ -0,0 +1,51 @@ +package re; + +=head1 NAME + +re - Perl pragma to alter regular expression behaviour + +=head1 SYNOPSIS + + ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here + + use re "taint"; + ($x) = ($^X =~ /^(.*)$/s); # $x _is_ tainted here + +=head1 DESCRIPTION + +When C is in effect, and a tainted string is the target +of a regex, the regex memories (or values returned by the m// operator +in list context) are tainted. + +This feature is useful when regex operations on tainted data aren't +meant to extract safe substrings, but to perform other transformations. + +See L. + +=cut + +my %bitmask = ( +taint => 0x00001000 +); + +sub bits { + my $bits = 0; + unless(@_) { + require Carp; + Carp::carp("Useless use of \"re\" pragma"); + } + foreach my $s (@_){ $bits |= $bitmask{$s} || 0; }; + $bits; +} + +sub import { + shift; + $^H |= bits(@_); +} + +sub unimport { + shift; + $^H &= ~ bits(@_); +} + +1; diff --git a/mg.c b/mg.c index 4f0616f..b3dde0e 100644 --- a/mg.c +++ b/mg.c @@ -478,8 +478,7 @@ magic_get(SV *sv, MAGIC *mg) } sv_setpvn(sv,s,i); if (tainting) - tainted = (was_tainted || RX_MATCH_TAINTED(rx) || - (curpm->op_pmflags & PMf_TAINTMEM)); + tainted = (was_tainted || RX_MATCH_TAINTED(rx)); break; } } diff --git a/op.c b/op.c index d5f0bb6..1af6d96 100644 --- a/op.c +++ b/op.c @@ -2100,8 +2100,11 @@ newPMOP(I32 type, I32 flags) pmop->op_flags = flags; pmop->op_private = 0 | (flags >> 8); + if (hints & HINT_RE_TAINT) + pmop->op_pmpermflags |= PMf_RETAINT; if (hints & HINT_LOCALE) - pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE); + pmop->op_pmpermflags |= PMf_LOCALE; + pmop->op_pmflags = pmop->op_pmpermflags; /* link into pm list */ if (type != OP_TRANS && curstash) { diff --git a/op.h b/op.h index fee95f7..9015028 100644 --- a/op.h +++ b/op.h @@ -189,8 +189,9 @@ struct pmop { }; #define PMdf_USED 0x01 /* pm has been used once already */ +#define PMdf_TAINTED 0x02 /* pm compiled from tainted pattern */ -#define PMf_TAINTMEM 0x0001 /* taint $1 etc. if target tainted */ +#define PMf_RETAINT 0x0001 /* taint $1 etc. if target tainted */ #define PMf_ONCE 0x0002 /* use pattern only once per reset */ #define PMf_REVERSED 0x0004 /* Should be matched right->left */ #define PMf_MAYBE_CONST 0x0008 /* replacement contains variables */ diff --git a/perl.h b/perl.h index 4a26b15..7f3fd63 100644 --- a/perl.h +++ b/perl.h @@ -1823,6 +1823,8 @@ typedef enum { #define HINT_NEW_RE 0x00010000 #define HINT_LOCALIZE_HH 0x00020000 /* %^H needs to be copied */ +#define HINT_RE_TAINT 0x00100000 + /* Various states of an input record separator SV (rs, nrs) */ #define RsSNARF(sv) (! SvOK(sv)) #define RsSIMPLE(sv) (SvOK(sv) && SvCUR(sv)) diff --git a/pod/perlmodlib.pod b/pod/perlmodlib.pod index 9511f55..5d0e5b0 100644 --- a/pod/perlmodlib.pod +++ b/pod/perlmodlib.pod @@ -79,6 +79,10 @@ restrict named opcodes when compiling or running Perl code overload basic Perl operations +=item re + +alter behaviour of regular expressions + =item sigtrap enable simple signal handling diff --git a/pod/perlop.pod b/pod/perlop.pod index 5232278..216f83c 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -750,7 +750,6 @@ Options are: m Treat string as multiple lines. o Compile pattern only once. s Treat string as single line. - t Taint $1 etc. if target string is tainted. x Use extended regular expressions. If "/" is the delimiter then the initial C is optional. With the C diff --git a/pp_ctl.c b/pp_ctl.c index f1c0669..f121b7e 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -67,7 +67,8 @@ PP(pp_regcmaybe) return NORMAL; } -PP(pp_regcomp) { +PP(pp_regcomp) +{ djSP; register PMOP *pm = (PMOP*)cLOGOP->op_other; register char *t; @@ -76,12 +77,12 @@ PP(pp_regcomp) { MAGIC *mg = Null(MAGIC*); tmpstr = POPs; - if(SvROK(tmpstr)) { + if (SvROK(tmpstr)) { SV *sv = SvRV(tmpstr); if(SvMAGICAL(sv)) mg = mg_find(sv, 'r'); } - if(mg) { + if (mg) { regexp *re = (regexp *)mg->mg_obj; ReREFCNT_dec(pm->op_pmregexp); pm->op_pmregexp = ReREFCNT_inc(re); @@ -89,6 +90,15 @@ PP(pp_regcomp) { else { t = SvPV(tmpstr, len); +#ifndef INCOMPLETE_TAINTS + if (tainting) { + if (tainted) + pm->op_pmdynflags |= PMdf_TAINTED; + else + pm->op_pmdynflags &= ~PMdf_TAINTED; + } +#endif + /* Check against the last compiled regexp. */ if (!pm->op_pmregexp || !pm->op_pmregexp->precomp || pm->op_pmregexp->prelen != len || diff --git a/pp_hot.c b/pp_hot.c index bd8a74e..b81ec56 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -786,6 +786,7 @@ PP(pp_match) I32 safebase; char *truebase; register REGEXP *rx = pm->op_pmregexp; + bool rxtainted; I32 gimme = GIMME; STRLEN len; I32 minmatch = 0; @@ -804,6 +805,8 @@ PP(pp_match) strend = s + len; if (!s) DIE("panic: do_match"); + rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) || + (tainted && (pm->op_pmflags & PMf_RETAINT))); TAINT_NOT; if (pm->op_pmdynflags & PMdf_USED) { @@ -910,7 +913,7 @@ play_it_again: /*NOTREACHED*/ gotcha: - TAINT_IF(RX_MATCH_TAINTED(rx)); + RX_MATCH_TAINTED_SET(rx, rxtainted); if (gimme == G_ARRAY) { I32 iters, i, len; @@ -963,7 +966,7 @@ play_it_again: } yup: /* Confirmed by check_substr */ - TAINT_IF(RX_MATCH_TAINTED(rx)); + RX_MATCH_TAINTED_SET(rx, rxtainted); ++BmUSEFUL(rx->check_substr); curpm = pm; if (pm->op_pmflags & PMf_ONCE) @@ -1520,7 +1523,10 @@ PP(pp_subst) s = SvPV(TARG, len); if (!SvPOKp(TARG) || SvTYPE(TARG) == SVt_PVGV) force_on_match = 1; - rxtainted = tainted << 1; + rxtainted = ((pm->op_pmdynflags & PMdf_TAINTED) || + (tainted && (pm->op_pmflags & PMf_RETAINT))); + if (tainted) + rxtainted |= 2; TAINT_NOT; force_it: diff --git a/t/lib/basename.t b/t/lib/basename.t index 860b337..a02aa32 100755 --- a/t/lib/basename.t +++ b/t/lib/basename.t @@ -1,4 +1,4 @@ -#!./perl +#!./perl -T BEGIN { chdir 't' if -d 't'; @@ -7,7 +7,7 @@ BEGIN { use File::Basename qw(fileparse basename dirname); -print "1..34\n"; +print "1..36\n"; # import correctly? print +(defined(&basename) && !defined(&fileparse_set_fstype) ? @@ -119,3 +119,21 @@ File::Basename::fileparse_set_fstype 'UNIX'; print +(dirname('/perl/') eq '/' ? '' : 'not '), "ok 33\n"; # perl5.003_18 gives '/perl/lib' print +(dirname('/perl/lib//') eq '/perl' ? '' : 'not '), "ok 34\n"; + +# The empty tainted value, for tainting strings +my $TAINT = substr($^X, 0, 0); +# How to identify taint when you see it +sub any_tainted (@) { + not eval { join("",@_), kill 0; 1 }; +} +sub tainted ($) { + any_tainted @_; +} +sub all_tainted (@) { + for (@_) { return 0 unless tainted $_ } + 1; +} + +print +(tainted(dirname($TAINT.'/perl/lib//')) ? '' : 'not '), "ok 35\n"; +print +(all_tainted(fileparse($TAINT.'/dir/draft.book7','\.book\d+')) + ? '' : 'not '), "ok 36\n"; diff --git a/t/op/taint.t b/t/op/taint.t index 5f85b36..f2181d8 100755 --- a/t/op/taint.t +++ b/t/op/taint.t @@ -83,7 +83,7 @@ print PROG 'print "@ARGV\n"', "\n"; close PROG; my $echo = "$Invoke_Perl $ECHO"; -print "1..145\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 @@ -187,16 +187,28 @@ print "1..145\n"; test 20, not tainted $foo; test 21, $foo eq 'bar'; - $foo = $1 if ('bar' . $TAINT) =~ /(.+)/t; - test 22, tainted $foo; - test 23, $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 24, tainted $pi; + test 28, tainted $pi; ($pi) = $pi =~ /(\d+\.\d+)/; - test 25, not tainted $pi; - test 26, 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 @@ -212,146 +224,146 @@ print "1..145\n"; }; close PROG; print `$Invoke_Perl "-T" $arg and some suspect arguments`; - test 27, !$?, "Exited with status $?"; + test 31, !$?, "Exited with status $?"; unlink $arg; } # Reading from a file should be tainted { my $file = './TEST'; - test 28, open(FILE, $file), "Couldn't open '$file': $!"; + test 32, open(FILE, $file), "Couldn't open '$file': $!"; my $block; sysread(FILE, $block, 100); my $line = ; close FILE; - test 29, tainted $block; - test 30, 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 (31..32) { print "ok $_\n"; } + for (35..36) { print "ok $_\n"; } } else { my @globs = eval { <*> }; - test 31, @globs == 0 && $@ =~ /^Insecure dependency/; + test 35, @globs == 0 && $@ =~ /^Insecure dependency/; @globs = eval { glob '*' }; - test 32, @globs == 0 && $@ =~ /^Insecure dependency/; + test 36, @globs == 0 && $@ =~ /^Insecure dependency/; } # Output of commands should be tainted { my $foo = `$echo abc`; - test 33, tainted $foo; + test 37, tainted $foo; } # Certain system variables should be tainted { - test 34, all_tainted $^X, $0; + test 38, all_tainted $^X, $0; } # Results of matching should all be untainted { my $foo = "abcdefghi" . $TAINT; - test 35, tainted $foo; + test 39, tainted $foo; $foo =~ /def/; - test 36, not any_tainted $`, $&, $'; + test 40, not any_tainted $`, $&, $'; $foo =~ /(...)(...)(...)/; - test 37, not any_tainted $1, $2, $3, $+; + test 41, not any_tainted $1, $2, $3, $+; my @bar = $foo =~ /(...)(...)(...)/; - test 38, not any_tainted @bar; + test 42, not any_tainted @bar; - test 39, tainted $foo; # $foo should still be tainted! - test 40, $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 41, eval { chmod 0, $TAINT } eq '', 'chmod'; - test 42, $@ =~ /^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 43, eval { truncate 'NoSuChFiLe', $TAINT0 } eq '', 'truncate'; - test 44, $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@; + test 47, eval { truncate 'NoSuChFiLe', $TAINT0 } eq '', 'truncate'; + test 48, $@ =~ /^(?:Insecure dependency|truncate not implemented)/, $@; - test 45, eval { rename '', $TAINT } eq '', 'rename'; - test 46, $@ =~ /^Insecure dependency/, $@; + test 49, eval { rename '', $TAINT } eq '', 'rename'; + test 50, $@ =~ /^Insecure dependency/, $@; - test 47, eval { unlink $TAINT } eq '', 'unlink'; - test 48, $@ =~ /^Insecure dependency/, $@; + test 51, eval { unlink $TAINT } eq '', 'unlink'; + test 52, $@ =~ /^Insecure dependency/, $@; - test 49, eval { utime $TAINT } eq '', 'utime'; - test 50, $@ =~ /^Insecure dependency/, $@; + test 53, eval { utime $TAINT } eq '', 'utime'; + test 54, $@ =~ /^Insecure dependency/, $@; if ($Config{d_chown}) { - test 51, eval { chown -1, -1, $TAINT } eq '', 'chown'; - test 52, $@ =~ /^Insecure dependency/, $@; + test 55, eval { chown -1, -1, $TAINT } eq '', 'chown'; + test 56, $@ =~ /^Insecure dependency/, $@; } else { - for (51..52) { print "ok $_ # Skipped: chown() is not available\n" } + for (55..56) { print "ok $_ # Skipped: chown() is not available\n" } } if ($Config{d_link}) { - test 53, eval { link $TAINT, '' } eq '', 'link'; - test 54, $@ =~ /^Insecure dependency/, $@; + test 57, eval { link $TAINT, '' } eq '', 'link'; + test 58, $@ =~ /^Insecure dependency/, $@; } else { - for (53..54) { print "ok $_ # Skipped: link() is not available\n" } + for (57..58) { print "ok $_ # Skipped: link() is not available\n" } } if ($Config{d_symlink}) { - test 55, eval { symlink $TAINT, '' } eq '', 'symlink'; - test 56, $@ =~ /^Insecure dependency/, $@; + test 59, eval { symlink $TAINT, '' } eq '', 'symlink'; + test 60, $@ =~ /^Insecure dependency/, $@; } else { - for (55..56) { 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. { - test 57, eval { mkdir $TAINT0, $TAINT } eq '', 'mkdir'; - test 58, $@ =~ /^Insecure dependency/, $@; + test 61, eval { mkdir $TAINT0, $TAINT } eq '', 'mkdir'; + test 62, $@ =~ /^Insecure dependency/, $@; - test 59, eval { rmdir $TAINT } eq '', 'rmdir'; - test 60, $@ =~ /^Insecure dependency/, $@; + test 63, eval { rmdir $TAINT } eq '', 'rmdir'; + test 64, $@ =~ /^Insecure dependency/, $@; - test 61, eval { chdir $TAINT } eq '', 'chdir'; - test 62, $@ =~ /^Insecure dependency/, $@; + test 65, eval { chdir $TAINT } eq '', 'chdir'; + test 66, $@ =~ /^Insecure dependency/, $@; if ($Config{d_chroot}) { - test 63, eval { chroot $TAINT } eq '', 'chroot'; - test 64, $@ =~ /^Insecure dependency/, $@; + test 67, eval { chroot $TAINT } eq '', 'chroot'; + test 68, $@ =~ /^Insecure dependency/, $@; } else { - for (63..64) { 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; - test 65, eval { require $foo } eq '', 'require'; - test 66, $@ =~ /^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 67, eval { open FOO, $foo } eq '', 'open for read'; - test 68, $@ eq '', $@; # NB: This should be allowed - test 69, $! == 2 || ($Is_Dos && $! == 22); # File not found + test 71, eval { open FOO, $foo } eq '', 'open for read'; + test 72, $@ eq '', $@; # NB: This should be allowed + test 73, $! == 2 || ($Is_Dos && $! == 22); # File not found - test 70, eval { open FOO, "> $foo" } eq '', 'open for write'; - test 71, $@ =~ /^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 @@ -359,67 +371,67 @@ else { my $foo = $TAINT; if ($^O eq 'amigaos') { - for (72..75) { print "ok $_ # Skipped: open('|') is not available\n" } + for (76..79) { print "ok $_ # Skipped: open('|') is not available\n" } } else { - test 72, eval { open FOO, "| $foo" } eq '', 'popen to'; - test 73, $@ =~ /^Insecure dependency/, $@; + test 76, eval { open FOO, "| $foo" } eq '', 'popen to'; + test 77, $@ =~ /^Insecure dependency/, $@; - test 74, eval { open FOO, "$foo |" } eq '', 'popen from'; - test 75, $@ =~ /^Insecure dependency/, $@; + test 78, eval { open FOO, "$foo |" } eq '', 'popen from'; + test 79, $@ =~ /^Insecure dependency/, $@; } - test 76, eval { exec $TAINT } eq '', 'exec'; - test 77, $@ =~ /^Insecure dependency/, $@; + test 80, eval { exec $TAINT } eq '', 'exec'; + test 81, $@ =~ /^Insecure dependency/, $@; - test 78, eval { system $TAINT } eq '', 'system'; - test 79, $@ =~ /^Insecure dependency/, $@; + test 82, eval { system $TAINT } eq '', 'system'; + test 83, $@ =~ /^Insecure dependency/, $@; $foo = "*"; taint_these $foo; - test 80, eval { `$echo 1$foo` } eq '', 'backticks'; - test 81, $@ =~ /^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 82, join('', eval { glob $foo } ) ne '', 'globbing'; - test 83, $@ eq '', $@; + test 86, join('', eval { glob $foo } ) ne '', 'globbing'; + test 87, $@ eq '', $@; } else { - for (82..83) { 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. { - test 84, eval { kill 0, $TAINT } eq '', 'kill'; - test 85, $@ =~ /^Insecure dependency/, $@; + test 88, eval { kill 0, $TAINT } eq '', 'kill'; + test 89, $@ =~ /^Insecure dependency/, $@; if ($Config{d_setpgrp}) { - test 86, eval { setpgrp 0, $TAINT } eq '', 'setpgrp'; - test 87, $@ =~ /^Insecure dependency/, $@; + test 90, eval { setpgrp 0, $TAINT } eq '', 'setpgrp'; + test 91, $@ =~ /^Insecure dependency/, $@; } else { - for (86..87) { print "ok $_ # Skipped: setpgrp() is not available\n" } + for (90..91) { print "ok $_ # Skipped: setpgrp() is not available\n" } } if ($Config{d_setprior}) { - test 88, eval { setpriority 0, $TAINT, $TAINT } eq '', 'setpriority'; - test 89, $@ =~ /^Insecure dependency/, $@; + test 92, eval { setpriority 0, $TAINT, $TAINT } eq '', 'setpriority'; + test 93, $@ =~ /^Insecure dependency/, $@; } else { - for (88..89) { 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}) { - test 90, eval { syscall $TAINT } eq '', 'syscall'; - test 91, $@ =~ /^Insecure dependency/, $@; + test 94, eval { syscall $TAINT } eq '', 'syscall'; + test 95, $@ =~ /^Insecure dependency/, $@; } else { - for (90..91) { print "ok $_ # Skipped: syscall() is not available\n" } + for (94..95) { print "ok $_ # Skipped: syscall() is not available\n" } } { @@ -428,17 +440,17 @@ else { local *FOO; my $temp = "./taintC$$"; END { unlink $temp } - test 92, open(FOO, "> $temp"), "Couldn't open $temp for write: $!"; + test 96, open(FOO, "> $temp"), "Couldn't open $temp for write: $!"; - test 93, eval { ioctl FOO, $TAINT, $foo } eq '', 'ioctl'; - test 94, $@ =~ /^Insecure dependency/, $@; + test 97, eval { ioctl FOO, $TAINT, $foo } eq '', 'ioctl'; + test 98, $@ =~ /^Insecure dependency/, $@; if ($Config{d_fcntl}) { - test 95, eval { fcntl FOO, $TAINT, $foo } eq '', 'fcntl'; - test 96, $@ =~ /^Insecure dependency/, $@; + test 99, eval { fcntl FOO, $TAINT, $foo } eq '', 'fcntl'; + test 100, $@ =~ /^Insecure dependency/, $@; } else { - for (95..96) { print "ok $_ # Skipped: fcntl() is not available\n" } + for (99..100) { print "ok $_ # Skipped: fcntl() is not available\n" } } close FOO; @@ -449,65 +461,65 @@ else { { my $foo = 'abc' . $TAINT; my $fooref = \$foo; - test 97, not tainted $fooref; - test 98, tainted $$fooref; - test 99, 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 100, all_tainted $foo, $bar; - test 101, tainted($foo = $bar); - test 102, tainted($bar = $bar); - test 103, tainted($bar += $bar); - test 104, tainted($bar -= $bar); - test 105, tainted($bar *= $bar); - test 106, tainted($bar++); - test 107, tainted($bar /= $bar); - test 108, tainted($bar += 0); - test 109, tainted($bar -= 2); - test 110, tainted($bar *= -1); - test 111, tainted($bar /= 1); - test 112, tainted($bar--); - test 113, $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 114, not tainted $foo[0]; - test 115, tainted $foo[1]; - test 116, 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 117, not tainted $bar[0]; - test 118, tainted $bar[1]; - test 119, 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 120, not tainted $baz[0]; - test 121, tainted $baz[1]; - test 122, 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 123, not tainted $plugh[0]; - test 124, tainted $plugh[1]; - test 125, 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 126, not tainted ((&$nautilus)[0]); - test 127, tainted ((&$nautilus)[1]); - test 128, 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 129, not tainted $xyzzy[0]; - test 130, tainted $xyzzy[1]; - test 131, 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 132, not tainted ((&$red_october)[0]); - test 133, tainted ((&$red_october)[1]); - test 134, 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 135, not tainted $corge[0]; - test 136, tainted $corge[1]; - test 137, 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. @@ -517,7 +529,7 @@ else { setpwent(); my @getpwent = getpwent(); die "getpwent: $!\n" unless (@getpwent); - test 138,( 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] @@ -528,17 +540,17 @@ else { and not tainted $getpwent[8]); endpwent(); } else { - print "ok 138 # 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); - test 139, tainted $readdir; + test 143, tainted $readdir; closedir(OP); } else { - print "ok 139 # Skipped: readdir() is not available\n"; + for (143) { print "ok $_ # Skipped: readdir() is not available\n" } } if ($Config{d_readlink} && $Config{d_symlink}) { @@ -546,10 +558,10 @@ else { unlink($symlink); symlink("/something/naughty", $symlink) or die "symlink: $!\n"; my $readlink = readlink($symlink); - test 140, tainted $readlink; + test 144, tainted $readlink; unlink($symlink); } else { - print "ok 140 # Skipped: readlink() or symlink() is not available\n"; + for (144) { print "ok $_ # Skipped: readlink() or symlink() is not available\n"; } } } @@ -557,22 +569,22 @@ else { { my $why = "y"; my $j = "x" | $why; - test 141, not tainted $j; + test 145, not tainted $j; $why = $TAINT."y"; $j = "x" | $why; - test 142, tainted $j; + test 146, tainted $j; } # test target of substitution (regression bug) { my $why = $TAINT."y"; $why =~ s/y/z/; - test 143, tainted $why; + test 147, tainted $why; my $z = "[z]"; $why =~ s/$z/zee/; - test 144, tainted $why; + test 148, tainted $why; $why =~ s/e/'-'.$$/ge; - test 145, tainted $why; + test 149, tainted $why; } diff --git a/toke.c b/toke.c index 5d0f8f3..27571e4 100644 --- a/toke.c +++ b/toke.c @@ -4941,8 +4941,6 @@ void pmflag(U16 *pmfl, int ch) *pmfl |= PMf_MULTILINE; else if (ch == 's') *pmfl |= PMf_SINGLELINE; - else if (ch == 't') - *pmfl |= PMf_TAINTMEM; else if (ch == 'x') *pmfl |= PMf_EXTENDED; } @@ -4964,7 +4962,7 @@ scan_pat(char *start) pm = (PMOP*)newPMOP(OP_MATCH, 0); if (multi_open == '?') pm->op_pmflags |= PMf_ONCE; - while (*s && strchr("iogcmstx", *s)) + while (*s && strchr("iogcmsx", *s)) pmflag(&pm->op_pmflags,*s++); pm->op_pmpermflags = pm->op_pmflags; @@ -5014,7 +5012,7 @@ scan_subst(char *start) s++; es++; } - else if (strchr("iogcmstx", *s)) + else if (strchr("iogcmsx", *s)) pmflag(&pm->op_pmflags,*s++); else break;