This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: [ID 20020704.001] my $foo = $1 won't taint $foo (with use re 'taint')
authorHugo van der Sanden <hv@crypt.org>
Sun, 4 Aug 2002 17:40:30 +0000 (18:40 +0100)
committerhv <hv@crypt.org>
Sun, 4 Aug 2002 15:34:19 +0000 (15:34 +0000)
Message-id: <200208041640.g74GeUU25061@crypt.compulink.co.uk>

p4raw-id: //depot/perl@17678

mg.c
t/op/taint.t

diff --git a/mg.c b/mg.c
index 63de612..a3ce4c5 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -693,18 +693,24 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
 
              getrx:
                if (i >= 0) {
-                   bool was_tainted = FALSE;
-                   if (PL_tainting) {
-                       was_tainted = PL_tainted;
-                       PL_tainted = FALSE;
-                   }
                    sv_setpvn(sv, s, i);
-                   if (PL_reg_match_utf8 && is_utf8_string((U8*)s, i))
+                   if (PL_reg_match_utf8 && is_utf8_string((U8*)s, i))
                        SvUTF8_on(sv);
                    else
                        SvUTF8_off(sv);
                    if (PL_tainting)
-                       PL_tainted = (was_tainted || RX_MATCH_TAINTED(rx));
+                       PL_tainted = PL_tainted || !!RX_MATCH_TAINTED(rx);
+                   if (RX_MATCH_TAINTED(rx)) {
+                       MAGIC* mg = SvMAGIC(sv);
+                       MAGIC* mgt;
+                       SvMAGIC(sv) = mg->mg_moremagic;
+                       SvTAINT(sv);
+                       if ((mgt = SvMAGIC(sv))) {
+                           mg->mg_moremagic = mgt;
+                           SvMAGIC(sv) = mg;
+                       }
+                   } else
+                       SvTAINTED_off(sv);
                    break;
                }
            }
index 18b39dc..7e8d4c4 100755 (executable)
@@ -124,7 +124,7 @@ my $echo = "$Invoke_Perl $ECHO";
 
 my $TEST = catfile(curdir(), 'TEST');
 
-print "1..205\n";
+print "1..206\n";
 
 # First, let's make sure that Perl is checking the dangerous
 # environment variables. Maybe they aren't set yet, so we'll
@@ -971,3 +971,10 @@ else
 
     # If you add tests here update also the above skip block for VMS.
 }
+
+{
+    # [ID 20020704.001] taint propagation failure
+    use re 'taint';
+    $TAINT =~ /(.*)/;
+    test 206, tainted(my $foo = $1);
+}