Skip to content

Commit c76a4f8

Browse files
committed
Catch null pointer returns from PyCObject_AsVoidPtr and PyCObject_FromVoidPtr
This is reproducibly possible in Python 2.7 if the user turned PendingDeprecationWarning into an error, but it's theoretically also possible in earlier versions in case of exceptional conditions. backpatched to 8.0
1 parent 52ba9a5 commit c76a4f8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/pl/plpython/plpython.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plpython.c - python as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.148 2010/07/08 19:00:11 tgl Exp $
4+
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.149 2010/08/25 19:37:56 petere Exp $
55
*
66
*********************************************************************
77
*/
@@ -1315,6 +1315,8 @@ PLy_procedure_get(FunctionCallInfo fcinfo, Oid tgreloid)
13151315
elog(FATAL, "expected a PyCObject, didn't get one");
13161316

13171317
proc = PyCObject_AsVoidPtr(plproc);
1318+
if (!proc)
1319+
PLy_elog(ERROR, "PyCObject_AsVoidPtr() failed");
13181320
if (proc->me != plproc)
13191321
elog(FATAL, "proc->me != plproc");
13201322
/* did we find an up-to-date cache entry? */
@@ -1539,8 +1541,11 @@ PLy_procedure_create(HeapTuple procTup, Oid tgreloid, char *key)
15391541
PLy_procedure_compile(proc, procSource);
15401542

15411543
pfree(procSource);
1544+
procSource = NULL;
15421545

15431546
proc->me = PyCObject_FromVoidPtr(proc, NULL);
1547+
if (!proc->me)
1548+
PLy_elog(ERROR, "PyCObject_FromVoidPtr() failed");
15441549
PyDict_SetItemString(PLy_procedure_cache, key, proc->me);
15451550
}
15461551
PG_CATCH();

0 commit comments

Comments
 (0)