summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_procedure.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-02-16 21:08:15 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-02-16 21:08:15 -0500
commitb3ec98c8bdb2ceb6c0fe0cd15a6299bcd42cb1d3 (patch)
tree020076d93fab7c49c9eb5f18c528427a0c159dcb /src/pl/plpython/plpy_procedure.c
parent0d670b934fb2551f0affec8bacbc16d9ea3fdf47 (diff)
Make plpython cope with funny characters in function names.
A function name that's double-quoted in SQL can contain almost any characters, but we were using that name directly as part of the name generated for the Python-level function, and Python doesn't like anything that isn't pretty much a standard identifier. To fix, replace anything that isn't an ASCII letter or digit with an underscore in the generated name. This doesn't create any risk of duplicate Python function names because we were already appending the function OID to the generated name to ensure uniqueness. Per bug #13960 from Jim Nasby. Patch by Jim Nasby, modified a bit by me. Back-patch to all supported branches.
Diffstat (limited to 'src/pl/plpython/plpy_procedure.c')
-rw-r--r--src/pl/plpython/plpy_procedure.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/pl/plpython/plpy_procedure.c b/src/pl/plpython/plpy_procedure.c
index d278d6e7058..20923b4a767 100644
--- a/src/pl/plpython/plpy_procedure.c
+++ b/src/pl/plpython/plpy_procedure.c
@@ -145,6 +145,7 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
bool isnull;
int i,
rv;
+ char *ptr;
procStruct = (Form_pg_proc) GETSTRUCT(procTup);
rv = snprintf(procName, sizeof(procName),
@@ -154,6 +155,15 @@ PLy_procedure_create(HeapTuple procTup, Oid fn_oid, bool is_trigger)
if (rv >= sizeof(procName) || rv < 0)
elog(ERROR, "procedure name would overrun buffer");
+ /* Replace any not-legal-in-Python-names characters with '_' */
+ for (ptr = procName; *ptr; ptr++)
+ {
+ if (!((*ptr >= 'A' && *ptr <= 'Z') ||
+ (*ptr >= 'a' && *ptr <= 'z') ||
+ (*ptr >= '0' && *ptr <= '9')))
+ *ptr = '_';
+ }
+
proc = PLy_malloc(sizeof(PLyProcedure));
proc->proname = PLy_strdup(NameStr(procStruct->proname));
proc->pyname = PLy_strdup(procName);