diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-04-03 16:59:43 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-04-03 16:59:43 +0000 |
commit | cd331e4b845f9206aa89e4f31bb75a040fef87ba (patch) | |
tree | 136ad3b7a0ebfa337e8473372a97f61a3ebdd3ba /src/pl/plpython/plpython.c | |
parent | aa38153d22df190397f851cfbd4506f31f44557e (diff) | |
download | postgresql-cd331e4b845f9206aa89e4f31bb75a040fef87ba.tar.gz postgresql-cd331e4b845f9206aa89e4f31bb75a040fef87ba.zip |
Defend against possible crash if a plpython function does not specify names
for its arguments. Also add a regression test, since someone apparently
changed every single plpython test case to use only named parameters; else
we'd have noticed this sooner.
Euler Taveira de Oliveira, per a report from Alvaro
Diffstat (limited to 'src/pl/plpython/plpython.c')
-rw-r--r-- | src/pl/plpython/plpython.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index 4914899a899..61e4772e8bc 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -1,7 +1,7 @@ /********************************************************************** * plpython.c - python as a procedural language for PostgreSQL * - * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.119 2009/03/26 22:26:08 petere Exp $ + * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.120 2009/04/03 16:59:42 tgl Exp $ * ********************************************************************* */ @@ -1052,9 +1052,11 @@ PLy_function_build_args(FunctionCallInfo fcinfo, PLyProcedure * proc) arg = Py_None; } - if (PyList_SetItem(args, i, arg) == -1 || - (proc->argnames && - PyDict_SetItemString(proc->globals, proc->argnames[i], arg) == -1)) + if (PyList_SetItem(args, i, arg) == -1) + PLy_elog(ERROR, "PyList_SetItem() failed for PL/Python function \"%s\" while setting up arguments", proc->proname); + + if (proc->argnames && proc->argnames[i] && + PyDict_SetItemString(proc->globals, proc->argnames[i], arg) == -1) PLy_elog(ERROR, "PyDict_SetItemString() failed for PL/Python function \"%s\" while setting up arguments", proc->proname); arg = NULL; } @@ -1081,7 +1083,8 @@ PLy_function_delete_args(PLyProcedure * proc) return; for (i = 0; i < proc->nargs; i++) - PyDict_DelItemString(proc->globals, proc->argnames[i]); + if (proc->argnames[i]) + PyDict_DelItemString(proc->globals, proc->argnames[i]); } |