Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4 - Mailing list pgsql-bugs

From Tim Bunce
Subject Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4
Date
Msg-id 20100219130617.GG373@timac.local
Whole thread Raw
In response to Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4  (Tim Bunce <Tim.Bunce@pobox.com>)
Responses Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4
List pgsql-bugs
I've got the patch to Safe ready but the more I think about it the more
I think the right fix is for Safe to automatically fully load utf8.pm
(and utf8_heavy.pl) and to always share SWASHNEW itself.

Assuming perl5-porters agree then the next release of Safe will do that
ad this patch won't be needed. (Other than it possibly being worthwhile
to detect the 'bad' versions of Safe.)

Tim.

On Fri, Feb 19, 2010 at 09:30:41AM +0000, Tim Bunce wrote:
> On Thu, Feb 18, 2010 at 11:32:38AM -0700, Alex Hunsaker wrote:
> > On Thu, Feb 18, 2010 at 11:09, Tim Bunce <Tim.Bunce@pobox.com> wrote:
> > > The key line is:
> > >
> > >    *PLPerl::utf8::SWASHNEW = \&utf8::SWASHNEW;
> >
> > Hrm... It seems to work for me in HEAD and AFAICS we dont have that
> > line.  Did I just miss it?  Or did you happen to fix it in another way
> > with your refactoring?
>
> To be honest I'm not sure. I plan to look into that today.
>
> > Another Idea that comes to mind would be instead of (in ::mksafefunc):
> > my $subref = ->reval(sub {} );
> > $subref->();
> >
> > do:
> > my $subref = ->reval(sub {});
> > return sub { ->reval("$subreb->();"); }
> >
> > or something...
> >
> > I did a few quick tests but it failed miserably for me...  Im also not
> > fond of adding yet another closure. :)
>
> No amount of closure wrapping will fix the problem.
>
> > > This allows the perl regex logic to call the SWASHNEW method that's
> > > called when information from the Unicode character database is needed.
> > > (The lack of that method was causing the regex logic to think that the
> > > utf8 module wasn't loaded, so it would try to 'require' it but fail due
> > > to the restrictions of the Safe compartment.)
> >
> > Makes me think we might just be able to share some of utf8 package in the safe?
>
> I tried. The perl utf8.c code does a method lookup of SWASHNEW to decide
> if the utf8 module has been loaded. So if SWASHNEW is shared _before_
> utf8 is loaded *and used* then the method lookup works (it finds the
> shared stub) and the utf8 module never gets loaded.
>
> (The *and used* complication is due to utf8.pm being a thin wrapper with
> an AUTOLOAD trampoline that loads utf8_heavy.pl on first use. More fun.)
>
> I do have a patch for Safe that, if utf8 is loaded, will ensure it's
> 'used' and then auto-share SWASHNEW. That won't fix PostgreSQL 8.x
> though because utf8 isn't loaded at the time Safe->new is called.
>
> > > The rest of the patch is updates the surrounding code to the same
> > > simplified 'utf8fix' logic used in PostgreSQL 9.0, and the same Safe
> > > version checks.
> >
> > From a quick look it looks ok.
>
> Thanks.
>
> Tim.
>

pgsql-bugs by date:

Previous
From: Tim Bunce
Date:
Subject: Re: BUG #5334: Version 2.22 of Perl Safe module breaks UTF8 PostgreSQL 8.4
Next
From: big col
Date:
Subject: Re: BUG #4785: Installation fails