pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7586: PL/Perl problem
3+ messages / 3 participants
[nested] [flat]

* BUG #7586: PL/Perl problem
@ 2012-10-06 14:14 franco.ricci@phys.uniroma1.it
  2012-10-07 17:06 ` Re: BUG #7586: PL/Perl problem Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: franco.ricci@phys.uniroma1.it @ 2012-10-06 14:14 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      7586
Logged by:          Franco Ricci
Email address:      franco.ricci@phys.uniroma1.it
PostgreSQL version: 9.0.10
Operating system:   FreeBSD 9.0
Description:        

I wrote the following function in Perl to make some operations with LLRP
command in a RFID application:
----
CREATE OR REPLACE FUNCTION llrp_command.llrpenc_bytea(xml)
  RETURNS bytea AS
$BODY$
    use strict;
    use RFID::LLRP::Builder qw(encode_message);
   
    my $llrp_xml = shift;
    my $llrp_bin = encode_message($llrp_xml);

    my $tmp = "";
    for(my $i = 0; $i < length($llrp_bin); $i = $i + 1)
    {
       my $val = substr($llrp_bin, $i, 1);
       $tmp = $tmp . sprintf("\\%03o",ord($val));
    }
    $llrp_bin = $tmp;
    return $llrp_bin;
$BODY$
  LANGUAGE plperlu IMMUTABLE STRICT
  COST 100;
ALTER FUNCTION llrp_command.llrpenc_bytea(xml)
  OWNER TO "LLRP";
COMMENT ON FUNCTION llrp_command.llrpenc_bytea(xml) IS 'Encode a xml LLRP
message in LLRP binary format and escape it into bytea';
----

Until version 9.0.8 all works fine. Version 9.0.8, 9.0.9, 9.0.10 and 9.1.6
have some troubles.
In particular when I call llrpenc_bytea function:

SELECT llrp_command.llrpenc_bytea('<llrp:SET_READER_CONFIG
xmlns:llrp="http://www.llrp.org/ltk/schema/core/encoding/xml/1.0";
Version="1" MessageID="2">
  <llrp:ResetToFactoryDefault>0</llrp:ResetToFactoryDefault>
  <llrp:KeepaliveSpec>
    <llrp:KeepaliveTriggerType>Periodic</llrp:KeepaliveTriggerType>
    <llrp:PeriodicTriggerValue>30000</llrp:PeriodicTriggerValue>
  </llrp:KeepaliveSpec>
</llrp:SET_READER_CONFIG>');

it returns:
-----
ERROR:  Entity: line 1: parser error : Document is empty

^
Entity: line 1: parser error : Start tag expected, '<' not found

^
Compilation failed in require at line 3.
BEGIN failed--compilation aborted at line 3.
CONTEXT:  compilation of PL/Perl function "llrpenc_bytea"

********** Error **********

ERROR: Entity: line 1: parser error : Document is empty

^
Entity: line 1: parser error : Start tag expected, '<' not found

^
Compilation failed in require at line 3.
BEGIN failed--compilation aborted at line 3.
SQL state: 42601
Context: compilation of PL/Perl function "llrpenc_bytea"
--------

I tried to run the same script as a perl script and it runs fine so I think
the problem is not Perl.
Postgresql version 9.1.2 has no problem.
I think the bug is about as postgresql passes xml argument to perl
interpreter.
The same function with a text argument works well:

----
REATE OR REPLACE FUNCTION llrp_command.llrpenc_bytea(text)
  RETURNS bytea AS
$BODY$
    use strict;
    use RFID::LLRP::Builder qw(encode_message);
   
    my $llrp_xml = shift;
    my $llrp_bin = encode_message($llrp_xml);

    my $tmp = "";
    for(my $i = 0; $i < length($llrp_bin); $i = $i + 1)
    {
       my $val = substr($llrp_bin, $i, 1);
       $tmp = $tmp . sprintf("\\%03o",ord($val));
    }
    $llrp_bin = $tmp;
    return $llrp_bin;
$BODY$
  LANGUAGE plperlu IMMUTABLE STRICT
  COST 100;
ALTER FUNCTION llrp_command.llrpenc_bytea(text)
  OWNER TO "LLRP";
COMMENT ON FUNCTION llrp_command.llrpenc_bytea(text) IS 'Encode a xml LLRP
message in LLRP binary format and escape it into bytea';
----
 
Thanks a lot for your great work

Regards
Franco Ricci





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #7586: PL/Perl problem
  2012-10-06 14:14 BUG #7586: PL/Perl problem franco.ricci@phys.uniroma1.it
@ 2012-10-07 17:06 ` Tom Lane <tgl@sss.pgh.pa.us>
  2012-10-07 19:59   ` Re: BUG #7586: PL/Perl problem Franco Ricci <franco.ricci@phys.uniroma1.it>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2012-10-07 17:06 UTC (permalink / raw)
  To: franco.ricci@phys.uniroma1.it; +Cc: pgsql-bugs

franco.ricci@phys.uniroma1.it writes:
> I wrote the following function in Perl to make some operations with LLRP
> command in a RFID application:
> ----
> CREATE OR REPLACE FUNCTION llrp_command.llrpenc_bytea(xml)
>   RETURNS bytea AS
> $BODY$
>     use strict;
>     use RFID::LLRP::Builder qw(encode_message);

I don't know anything about RFID::LLRP::Builder, but some quick googling
suggests that it accesses libxml2 under the hood.  If so, and if it
relies on being able to fetch external entities, you're going to need to
use PG 9.2 to make this work.  The fix for CVE-2012-3489 broke such
cases in earlier branches.  Sorry about that, but the alternatives were
worse; and in any case, pre-9.2 versions never made any serious effort
to allow other uses of libxml2 inside the backend.  It's mostly luck
that it worked for you before, I think.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #7586: PL/Perl problem
  2012-10-06 14:14 BUG #7586: PL/Perl problem franco.ricci@phys.uniroma1.it
  2012-10-07 17:06 ` Re: BUG #7586: PL/Perl problem Tom Lane <tgl@sss.pgh.pa.us>
@ 2012-10-07 19:59   ` Franco Ricci <franco.ricci@phys.uniroma1.it>
  0 siblings, 0 replies; 3+ messages in thread

From: Franco Ricci @ 2012-10-07 19:59 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Thanks a lot for explanation.
I'm planing to upgrade to pgsql 9.2 even for other reasons.
If I need to use earlier postgresql versions I'll fix my functions using 
a text arguments instead of xml one.
I tried and It seams to work fine.

Regards
Franco Ricci





On 7-10-2012 7:06 PM, Tom Lane wrote:
> franco.ricci@phys.uniroma1.it writes:
>> I wrote the following function in Perl to make some operations with LLRP
>> command in a RFID application:
>> ----
>> CREATE OR REPLACE FUNCTION llrp_command.llrpenc_bytea(xml)
>>    RETURNS bytea AS
>> $BODY$
>>      use strict;
>>      use RFID::LLRP::Builder qw(encode_message);
> I don't know anything about RFID::LLRP::Builder, but some quick googling
> suggests that it accesses libxml2 under the hood.  If so, and if it
> relies on being able to fetch external entities, you're going to need to
> use PG 9.2 to make this work.  The fix for CVE-2012-3489 broke such
> cases in earlier branches.  Sorry about that, but the alternatives were
> worse; and in any case, pre-9.2 versions never made any serious effort
> to allow other uses of libxml2 inside the backend.  It's mostly luck
> that it worked for you before, I think.
>
> 			regards, tom lane
>


-- 
Franco Ricci
LabIT
Sviluppo Servizi Informatici

Dipartimento di Fisica
Università di Roma "La Sapienza"
Piazzale Aldo Moro, 5
00185
Roma
Italy

tel +390649913449
fax +39064463158

Attachments:

franco_ricci.vcf (text/x-vcard, 345B) download begin:vcard fn:Franco Ricci n:Ricci;Franco org;quoted-printable:Dipartimento di Fisica, Universit=C3=A0 di Roma "La Sapienza" adr:;;Piazzale Aldo Moro, 2;Roma;;00185;Italy email;internet:franco.ricci@phys.uniroma1.it, franco.ricci@uniroma1.it title:LabIT tel;work:+390649913449 tel;fax:+39064463158 url:www.phys.uniroma1.it version:2.1 end:vcard
^ permalink raw reply [nested|flat] 3+ messages in thread


end of thread, other threads:[~2012-10-07 19:59 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-10-06 14:14 BUG #7586: PL/Perl problem franco.ricci@phys.uniroma1.it
2012-10-07 17:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-10-07 19:59   ` Franco Ricci <franco.ricci@phys.uniroma1.it>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox