Re: Plperl Safe version check fails for Safe 2.09

Lists: pgsql-hackers
From: Mark Kirkwood <markir(at)coretech(dot)co(dot)nz>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Plperl Safe version check fails for Safe 2.09
Date: 2004-11-24 00:32:04
Message-ID: 41A3D684.4090702@coretech.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

It seems that the check in src/pl/plperl/plperl.c

eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);

is not working quite as expected (CVS HEAD from today):

I have Safe.pm at version 2.09, yet any plperl function I run fails with :

ERROR: error from function: trusted perl functions disabled - please
upgrade perl Safe module to at least 2.09 at (eval 4) line 1.

Just to be sure I amended the test code to :

elog(INFO, "Safe version = %f", safe_version);
eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);

and I see :

INFO: Safe version = 2.090000

(Followed by the error)

I confess some puzzlement - as the code *looks* like it should work!
The platform is Linux 2.4.22 glibc 2.3.2, perl 5.8.0 (Patched Redhat 9)

regards

Mark


From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Mark Kirkwood <markir(at)coretech(dot)co(dot)nz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Plperl Safe version check fails for Safe 2.09
Date: 2004-11-24 01:53:28
Message-ID: 41A3E998.80207@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Could be a rounding issue. What happens if you try this instead:?

eval_pv((safe_version <= 2.08 ? safe_bad : safe_ok), FALSE);

Alternatively, what happens if we make safe_version a double rather than
a float?

(If nothing else works we might have to fall back on a lexical comparison)

cheers

andrew

Mark Kirkwood wrote:

> It seems that the check in src/pl/plperl/plperl.c
>
> eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);
>
> is not working quite as expected (CVS HEAD from today):
>
> I have Safe.pm at version 2.09, yet any plperl function I run fails
> with :
>
> ERROR: error from function: trusted perl functions disabled - please
> upgrade perl Safe module to at least 2.09 at (eval 4) line 1.
>
> Just to be sure I amended the test code to :
>
> elog(INFO, "Safe version = %f", safe_version);
> eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);
>
> and I see :
>
> INFO: Safe version = 2.090000
>
> (Followed by the error)
>
> I confess some puzzlement - as the code *looks* like it should work!
> The platform is Linux 2.4.22 glibc 2.3.2, perl 5.8.0 (Patched Redhat 9)
>
> regards
>
> Mark
>
>
>
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>


From: Mark Kirkwood <markir(at)coretech(dot)co(dot)nz>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Plperl Safe version check fails for Safe 2.09
Date: 2004-11-24 04:07:11
Message-ID: 41A408EF.5060306@coretech.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

A bit more thinking led me to try:

float safe_version;
...
eval_pv((safe_version < (float)2.09 ? safe_bad : safe_ok), FALSE);

which seems to fix the issue. (after all float *should* be accurate
enough in this case)

cheers

Mark

P.s : trivial patch attached

Andrew Dunstan wrote:

>
> Could be a rounding issue. What happens if you try this instead:?
>
> eval_pv((safe_version <= 2.08 ? safe_bad : safe_ok), FALSE);
>
> Alternatively, what happens if we make safe_version a double rather
> than a float?
>
> (If nothing else works we might have to fall back on a lexical
> comparison)
>
> cheers
>
> andrew
>

Attachment Content-Type Size
plperl.c.diff text/plain 323 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mark Kirkwood <markir(at)coretech(dot)co(dot)nz>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Plperl Safe version check fails for Safe 2.09
Date: 2004-11-24 04:56:26
Message-ID: 3895.1101272186@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Mark Kirkwood <markir(at)coretech(dot)co(dot)nz> writes:
> It seems that the check in src/pl/plperl/plperl.c
> eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);
> is not working quite as expected (CVS HEAD from today):

Yah know, I looked at that on Monday and said to myself "Self, that
looks like a rounding problem waiting to happen" ... but in the absence
of a trouble report didn't want to mess with it.

Part of the problem is that Perl NV is double, not float, and so the
declaration of safe_version is wrong on its face. But even with it
properly declared, exact comparison of double values is playing with
fire. I'd be inclined to change it to something like

double safe_version;
...
if (safe_version < 2.0899999) ...

regards, tom lane


From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <markir(at)coretech(dot)co(dot)nz>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Plperl Safe version check fails for Safe 2.09
Date: 2004-11-24 17:29:19
Message-ID: 2473.24.211.141.25.1101317359.squirrel@www.dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane said:
> Mark Kirkwood <markir(at)coretech(dot)co(dot)nz> writes:
>> It seems that the check in src/pl/plperl/plperl.c
>> eval_pv((safe_version < 2.09 ? safe_bad : safe_ok), FALSE);
>> is not working quite as expected (CVS HEAD from today):
>
> Yah know, I looked at that on Monday and said to myself "Self, that
> looks like a rounding problem waiting to happen" ... but in the absence
> of a trouble report didn't want to mess with it.
>
> Part of the problem is that Perl NV is double, not float, and so the
> declaration of safe_version is wrong on its face. But even with it
> properly declared, exact comparison of double values is playing with
> fire. I'd be inclined to change it to something like
>
> double safe_version;
> ...
> if (safe_version < 2.0899999) ...
>

Since there was no released version between 2.08 and 2.09, comparing to
2.085 should do the trick (or any of 2.08[1-9]).

cheers

andrew