[PATCH] fix for [perl #61976] Errno ($!) not evaluated to a error message string (5.10.0 in taint mode)
David Mitchell
davem at iabyn.com
Mon Jan 11 21:42:07 UTC 2010
Change 27176 / 2a509ed3c095f7d712013e653f68821f6bb2d6db fixed a taint
bug, which as a side effect, meant that $! used within a tainted expression
failed to have a string value.
This quick fix just makes sure the POK flag is set (prior to it being
shifted back to pPOK).
---
mg.c | 1 +
t/op/taint.t | 13 ++++++++++++-
2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/mg.c b/mg.c
index fb91325..ddfc2ff 100644
--- a/mg.c
+++ b/mg.c
@@ -1048,6 +1048,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
else
#endif
sv_setpv(sv, errno ? Strerror(errno) : "");
+ SvPOK_on(sv); /* may have got removed during taint processing */
RESTORE_ERRNO;
}
#endif
diff --git a/t/op/taint.t b/t/op/taint.t
index 796b6fa..161073d 100644
--- a/t/op/taint.t
+++ b/t/op/taint.t
@@ -17,7 +17,7 @@ use Config;
use File::Spec::Functions;
BEGIN { require './test.pl'; }
-plan tests => 301;
+plan tests => 302;
$| = 1;
@@ -1308,6 +1308,17 @@ foreach my $ord (78, 163, 256) {
ok(tainted($zz), "pack a*a* preserves tainting");
}
+# Bug RT #61976 tainted $! would show numeric rather than string value
+
+{
+ my $tainted_path = substr($^X,0,0) . "/no/such/file";
+ my $err;
+ # $! is used in a tainted expression, so gets tainted
+ open my $fh, $tainted_path or $err= "$!";
+ unlike($err, qr/^\d+$/, 'tainted $!');
+}
+
+
# This may bomb out with the alarm signal so keep it last
SKIP: {
skip "No alarm()" unless $Config{d_alarm};
--
1.7.0
--ZPt4rx8FFjLCG7dd--
More information about the Perl-maintainers
mailing list