From: Jim Nasby <Jim.Nasby@BlueTreble.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13960: plpython fails with certain function names
Date: Tue, 16 Feb 2016 19:23:38 -0600
Message-ID: <56C3CB9A.4030009@BlueTreble.com> (raw)
In-Reply-To: <4535.1455498553@sss.pgh.pa.us>
References: <20160215001447.2605.36302@wrigleys.postgresql.org>
<3868.1455497399@sss.pgh.pa.us>
<56C12241.2030107@BlueTreble.com>
<4535.1455498553@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On 2/14/16 7:09 PM, Tom Lane wrote:
> Yeah, that's what I was thinking about. But yes, if we append the OID
> anyway then we might as well just strip all non-alphanumeric chars
> from the name. Safe and you still get some debuggability.
Attached. I opted not to modify the name in-place. If it's safe to
modify in place, might want to just replace invalid characters with '_'
instead of making a copy.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:plpython_name.patch (text/plain, 3.3K) downloaddiff --git a/src/pl/plpython/expected/plpython_test.out b/src/pl/plpython/expected/plpython_test.outindex 7b76faf..f8270a7 100644--- a/src/pl/plpython/expected/plpython_test.out+++ b/src/pl/plpython/expected/plpython_test.out@@ -16,8 +16,8 @@ select stupidn();
zarkon
(1 row)
--- test multiple arguments-CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text+-- test multiple arguments and odd characters in function name+CREATE FUNCTION "Argument test #1"(u users, a1 text, a2 text) RETURNS text
AS
'keys = list(u.keys())
keys.sort()
@@ -27,8 +27,8 @@ for key in keys:
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
return words'
LANGUAGE plpythonu;
-select argument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;- argument_test_one +select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;+ Argument test #1
-----------------------------------------------------------------------
jane doe => {fname: jane, lname: doe, userid: 1, username: j_doe}
john doe => {fname: john, lname: doe, userid: 2, username: johnd}
diff --git a/src/pl/plpython/plpy_procedure.c b/src/pl/plpython/plpy_procedure.cindex e1f5620..4bfc43d 100644--- a/src/pl/plpython/plpy_procedure.c+++ b/src/pl/plpython/plpy_procedure.c@@ -141,6 +141,8 @@ static PLyProcedure *
PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
{
char procName[NAMEDATALEN + 256];
+ char rawProcName[NAMEDATALEN];+ char *ptr, *ptr2;
Form_pg_proc procStruct;
PLyProcedure *volatile proc;
MemoryContext cxt;
@@ -148,9 +150,22 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
int rv;
procStruct = (Form_pg_proc) GETSTRUCT(procTup);
++ /* Swap invalid chars with '_' before building full name */+ ptr = NameStr(procStruct->proname);+ ptr2 = rawProcName;+ while (*ptr)+ {+ if ( (*ptr >= 'A' && *ptr <= 'Z' ) ||+ (*ptr >= 'a' && *ptr <= 'z' ) ||+ (*ptr >= '0' && *ptr <= '9' ) )+ *ptr2++ = *ptr;+ ptr++;+ }+ *ptr2 = 0;
rv = snprintf(procName, sizeof(procName),
"__plpython_procedure_%s_%u",
- NameStr(procStruct->proname),+ rawProcName,
fn_oid);
if (rv >= sizeof(procName) || rv < 0)
elog(ERROR, "procedure name would overrun buffer");
diff --git a/src/pl/plpython/sql/plpython_test.sql b/src/pl/plpython/sql/plpython_test.sqlindex c8d5ef5..3a76104 100644--- a/src/pl/plpython/sql/plpython_test.sql+++ b/src/pl/plpython/sql/plpython_test.sql@@ -11,8 +11,8 @@ CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython2u;
select stupidn();
--- test multiple arguments-CREATE FUNCTION argument_test_one(u users, a1 text, a2 text) RETURNS text+-- test multiple arguments and odd characters in function name+CREATE FUNCTION "Argument test #1"(u users, a1 text, a2 text) RETURNS text
AS
'keys = list(u.keys())
keys.sort()
@@ -23,7 +23,7 @@ words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
return words'
LANGUAGE plpythonu;
-select argument_test_one(users, fname, lname) from users where lname = 'doe' order by 1;+select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
-- check module contents
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: Jim.Nasby@BlueTreble.com, tgl@sss.pgh.pa.us
Subject: Re: BUG #13960: plpython fails with certain function names
In-Reply-To: <56C3CB9A.4030009@BlueTreble.com>
References: <20160215001447.2605.36302@wrigleys.postgresql.org> <3868.1455497399@sss.pgh.pa.us> <56C12241.2030107@BlueTreble.com> <4535.1455498553@sss.pgh.pa.us> <56C3CB9A.4030009@BlueTreble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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