mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Ensure plperl strings are always correctly UTF8 encoded.
Amit Khandekar and Alex Hunsaker. Backpatched to 9.1 where the problem first occurred.
This commit is contained in:
parent
6b5510e8d6
commit
e75d41f0c3
@ -57,7 +57,7 @@ PSQLDIR = $(bindir)
|
|||||||
|
|
||||||
include $(top_srcdir)/src/Makefile.shlib
|
include $(top_srcdir)/src/Makefile.shlib
|
||||||
|
|
||||||
plperl.o: perlchunks.h plperl_opmask.h
|
plperl.o: perlchunks.h plperl_opmask.h plperl_helpers.h
|
||||||
|
|
||||||
plperl_opmask.h: plperl_opmask.pl
|
plperl_opmask.h: plperl_opmask.pl
|
||||||
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
|
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
|
||||||
|
@ -650,6 +650,16 @@ CONTEXT: PL/Perl anonymous code block
|
|||||||
DO $do$ use warnings FATAL => qw(void) ; my @y; my $x = sort @y; 1; $do$ LANGUAGE plperl;
|
DO $do$ use warnings FATAL => qw(void) ; my @y; my $x = sort @y; 1; $do$ LANGUAGE plperl;
|
||||||
ERROR: Useless use of sort in scalar context at line 1.
|
ERROR: Useless use of sort in scalar context at line 1.
|
||||||
CONTEXT: PL/Perl anonymous code block
|
CONTEXT: PL/Perl anonymous code block
|
||||||
|
--
|
||||||
|
-- Make sure strings are validated
|
||||||
|
-- Should fail for all encodings, as nul bytes are never permitted.
|
||||||
|
--
|
||||||
|
CREATE OR REPLACE FUNCTION perl_zerob() RETURNS TEXT AS $$
|
||||||
|
return "abcd\0efg";
|
||||||
|
$$ LANGUAGE plperlu;
|
||||||
|
SELECT perl_zerob();
|
||||||
|
ERROR: invalid byte sequence for encoding "UTF8": 0x00
|
||||||
|
CONTEXT: PL/Perl function "perl_zerob"
|
||||||
-- make sure functions marked as VOID without an explicit return work
|
-- make sure functions marked as VOID without an explicit return work
|
||||||
CREATE OR REPLACE FUNCTION myfuncs() RETURNS void AS $$
|
CREATE OR REPLACE FUNCTION myfuncs() RETURNS void AS $$
|
||||||
$_SHARED{myquote} = sub {
|
$_SHARED{myquote} = sub {
|
||||||
|
@ -7,10 +7,21 @@
|
|||||||
static inline char *
|
static inline char *
|
||||||
utf_u2e(const char *utf8_str, size_t len)
|
utf_u2e(const char *utf8_str, size_t len)
|
||||||
{
|
{
|
||||||
char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, GetDatabaseEncoding());
|
int enc = GetDatabaseEncoding();
|
||||||
|
|
||||||
|
char *ret = (char *) pg_do_encoding_conversion((unsigned char *) utf8_str, len, PG_UTF8, enc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* when we are a PG_UTF8 or SQL_ASCII database
|
||||||
|
* pg_do_encoding_conversion() will not do any conversion or
|
||||||
|
* verification. we need to do it manually instead.
|
||||||
|
*/
|
||||||
|
if (enc == PG_UTF8 || enc == PG_SQL_ASCII)
|
||||||
|
pg_verify_mbstr_len(PG_UTF8, utf8_str, len, false);
|
||||||
|
|
||||||
if (ret == utf8_str)
|
if (ret == utf8_str)
|
||||||
ret = pstrdup(ret);
|
ret = pstrdup(ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,6 +423,15 @@ DO $do$ use strict; my $name = "foo"; my $ref = $$name; $do$ LANGUAGE plperl;
|
|||||||
-- yields "ERROR: Useless use of sort in scalar context."
|
-- yields "ERROR: Useless use of sort in scalar context."
|
||||||
DO $do$ use warnings FATAL => qw(void) ; my @y; my $x = sort @y; 1; $do$ LANGUAGE plperl;
|
DO $do$ use warnings FATAL => qw(void) ; my @y; my $x = sort @y; 1; $do$ LANGUAGE plperl;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Make sure strings are validated
|
||||||
|
-- Should fail for all encodings, as nul bytes are never permitted.
|
||||||
|
--
|
||||||
|
CREATE OR REPLACE FUNCTION perl_zerob() RETURNS TEXT AS $$
|
||||||
|
return "abcd\0efg";
|
||||||
|
$$ LANGUAGE plperlu;
|
||||||
|
SELECT perl_zerob();
|
||||||
|
|
||||||
-- make sure functions marked as VOID without an explicit return work
|
-- make sure functions marked as VOID without an explicit return work
|
||||||
CREATE OR REPLACE FUNCTION myfuncs() RETURNS void AS $$
|
CREATE OR REPLACE FUNCTION myfuncs() RETURNS void AS $$
|
||||||
$_SHARED{myquote} = sub {
|
$_SHARED{myquote} = sub {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user