develooper Front page | perl.perl5.porters | Postings from April 2012

[perl #33186] Testing for taint and utf8 on magic values

Thread Previous
From:
Brian Fraser via RT
Date:
April 30, 2012 00:40
Subject:
[perl #33186] Testing for taint and utf8 on magic values
Message ID:
rt-3.6.HEAD-4610-1335757632-646.33186-15-0@perl.org
On Sun Dec 26 17:35:35 2004, ysth wrote:
> On Mon, Dec 27, 2004 at 01:27:27AM +0000, Ton Hospel <perl5-
> porters@ton.iguana.be> wrote:
> > In article <20041226230112.GA3552@e_n.org>,
> > 	Yitzchak Scott-Thoennes <sthoenna@efn.org> writes:
> > > That's insufficient for overloading (which isn't handled like
> regular
> > > magic).  I'd suggest just going ahead and doing an SvPV.
> > >
> > mm, didn't know that, that makes some of my XS code incomplete then.
> > But SvPV seems apporpiate enough here.
> 
> The rule is, you can only check the UTF8 flag *after* calling SvPV
> (at least for 5.8.1 and later - before that only a direct stringify
> like "$x" would preserve the UTF8 flag).  Same thing with stringified
> Regexp's that contain utf8 literals.
> 

Running this on 5.14.2 and blead, I get:
$ perl -wlT 33186.pl 
0
Can't locate object method "FETCH" via package "main" at 33186.pl line 10.

So utf8::is_utf8() was fixed, but tainted() was not. I tried with both
the XS and PP versions and got the same result.
For the XS version, the issue is in the core itself, since sv_tainted()
isn't calling get magic before checking for taintedness. So I just went
and added a SvGETMAGIC(sv); to sv_taint(). That solves this ticket (and
one TODO) but breaks one test in t/op/taint.t:

{
    # Bug ID 20010730.010

    my $i = 0;

    sub Tie::TIESCALAR {
        my $class =  shift;
        my $arg   =  shift;

        bless \$arg => $class;
    }

    sub Tie::FETCH {
        $i ++;
        ${$_ [0]}
    }

 
    package main;
 
    my $bar = "The Big Bright Green Pleasure Machine";
    taint_these $bar;
    tie my ($foo), Tie => $bar;

    my $baz = $foo;

    ok $i == 1;
}

Because now FETCH gets called twice, so $i ends up as 2. Unfortunately I
can't find the bug report that the test references, and I'm already way
out of my depth here, so this is as far as I can go -- Could someone
else take a look?


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=33186

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About