Subject: | tainted() does not localize $SIG{__DIE__} |
tainted() does not re-localize eval() when performing the taint check.
This is important because if a test is run with Test::Taint under
Devel::Cover, the test will be incorrectly flagged as dying despite the
fact that the tests completed successfully.
Attached is a patch against Test-Taint-1.04, which localizes
$SIG{__DIE__} inside the eval.
Subject: | Test-Taint-1.04.patch |
diff -ur Test-Taint-1.04-orig/t/tainted.t Test-Taint-1.04/t/tainted.t
--- Test-Taint-1.04-orig/t/tainted.t 2004-02-04 00:33:37.000000000 -0600
+++ Test-Taint-1.04/t/tainted.t 2006-11-20 12:40:09.000000000 -0600
@@ -1,6 +1,6 @@
#!perl -T
-use Test::More tests=>4;
+use Test::More tests=>7;
BEGIN { use_ok( 'Test::Taint' ); }
@@ -13,3 +13,11 @@
my $foo = 43;
ok( !tainted($foo), "43 is not tainted" );
+RESET_SIG_DIE: {
+ my $counter = 0;
+ local $SIG{__DIE__} = sub { $counter++ };
+ ok( tainted($ENV{$key}), "\$ENV{$key} is tainted" );
+ cmp_ok($counter, '==', 0, 'counter was not incremented (our die did not fire)');
+ eval { die "validly" };
+ cmp_ok($counter, '==', 1, 'counter was incremented (our die fired properly)');
+}
diff -ur Test-Taint-1.04-orig/Taint.pm Test-Taint-1.04/Taint.pm
--- Test-Taint-1.04-orig/Taint.pm 2004-08-09 22:06:57.000000000 -0500
+++ Test-Taint-1.04/Taint.pm 2006-11-20 12:29:21.000000000 -0600
@@ -237,7 +237,7 @@
sub tainted {
no warnings qw(void uninitialized);
- return !eval { join('', shift), kill 0; 1 };
+ return !eval { local $SIG{__DIE__} = 'DEFAULT'; join('', shift), kill 0; 1 };
} # tainted
=head2 tainted_deeply( I<$var> )