From: Radu Greab Date: Mon, 2 Oct 2000 22:03:44 +0000 (+0300) Subject: Re: [ID 20000912.008] substr replacement of tainted data (bug) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=35fba0d9b63c24c469494ae4d5dc6f37fed89345;p=p5sagit%2Fp5-mst-13.2.git Re: [ID 20000912.008] substr replacement of tainted data (bug) Message-ID: <14808.56336.594486.626712@busy.netsoft.ro> p4raw-id: //depot/perl@7111 --- diff --git a/op.c b/op.c index 4856d98..84a1df9 100644 --- a/op.c +++ b/op.c @@ -6463,6 +6463,22 @@ Perl_ck_trunc(pTHX_ OP *o) return ck_fun(o); } +OP * +Perl_ck_substr(pTHX_ OP *o) +{ + o = ck_fun(o); + if ((o->op_flags & OPf_KIDS) && o->op_private == 4) { + OP *kid = cLISTOPo->op_first; + + if (kid->op_type == OP_NULL) + kid = kid->op_sibling; + if (kid) + kid->op_flags |= OPf_MOD; + + } + return o; +} + /* A peephole optimizer. We visit the ops in the order they're to execute. */ void diff --git a/opcode.pl b/opcode.pl index d138917..43d98ae 100755 --- a/opcode.pl +++ b/opcode.pl @@ -515,7 +515,7 @@ abs abs ck_fun fsTu% S? # String stuff. length length ck_lengthconst isTu% S? -substr substr ck_fun st@ S S S? S? +substr substr ck_substr st@ S S S? S? vec vec ck_fun ist@ S S S index index ck_index isT@ S S S? diff --git a/t/op/substr.t b/t/op/substr.t index 891e904..4d3bbce 100755 --- a/t/op/substr.t +++ b/t/op/substr.t @@ -1,6 +1,6 @@ #!./perl -print "1..135\n"; +print "1..136\n"; #P = start of string Q = start of substr R = end of substr S = end of string @@ -297,3 +297,10 @@ ok 125, $a eq 'xxxxefgh'; ok 134, length($z) == 5; ok 135, $z eq "21\x{263a}10"; } + +# replacement should work on magical values +require Tie::Scalar; +my %data; +tie $data{'a'}, 'Tie::StdScalar'; # makes $data{'a'} magical +$data{a} = "firstlast"; +ok 136, substr($data{'a'}, 0, 5, "") eq "first" && $data{'a'} eq "last";