change 24943 broke restoration of localized taint values
authorDave Mitchell <davem@fdisolutions.com>
Tue, 5 Jul 2005 13:01:23 +0000 (13:01 +0000)
committerDave Mitchell <davem@fdisolutions.com>
Tue, 5 Jul 2005 13:01:23 +0000 (13:01 +0000)
p4raw-id: //depot/perl@25081

mg.c
t/op/taint.t

diff --git a/mg.c b/mg.c
index 086ab9a..9ae88c4 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -1921,10 +1921,13 @@ int
 Perl_magic_settaint(pTHX_ SV *sv, MAGIC *mg)
 {
     PERL_UNUSED_ARG(sv);
-    if (PL_tainted)
-       mg->mg_len |= 1;
-    else
-       mg->mg_len &= ~1;
+    /* update taint status unless we're restoring at scope exit */
+    if (PL_localizing != 2) {
+       if (PL_tainted)
+           mg->mg_len |= 1;
+       else
+           mg->mg_len &= ~1;
+    }
     return 0;
 }
 
index 119e419..9089d04 100755 (executable)
@@ -17,7 +17,7 @@ use Config;
 use File::Spec::Functions;
 
 BEGIN { require './test.pl'; }
-plan tests => 238;
+plan tests => 243;
 
 
 $| = 1;
@@ -1106,3 +1106,25 @@ TERNARY_CONDITIONALS: {
         test not any_tainted @bar;
     }
 }
+
+# at scope exit, a restored localised value should have its old
+# taint status, not the taint status of the current statement
+
+{
+    our $x99 = $^X;
+    test tainted $x99;
+
+    $x99 = '';
+    test not tainted $x99;
+
+    my $c = do { local $x99; $^X };
+    test not tainted $x99;
+}
+{
+    our $x99 = $^X;
+    test tainted $x99;
+
+    my $c = do { local $x99; '' };
+    test tainted $x99;
+}
+