]> granicus.if.org Git - postgresql/commitdiff
Catch null pointer returns from PyCObject_AsVoidPtr and PyCObject_FromVoidPtr
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 25 Aug 2010 19:37:34 +0000 (19:37 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 25 Aug 2010 19:37:34 +0000 (19:37 +0000)
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

src/pl/plpython/plpython.c

index 1a8c2ef857afa43ce51df9a74343a0fad5c070f5..630f481083f0d023874114b165feafd28de6d524 100644 (file)
@@ -29,7 +29,7 @@
  * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.66.2.9 2010/04/30 19:16:10 tgl Exp $
+ *     $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.66.2.10 2010/08/25 19:37:34 petere Exp $
  *
  *********************************************************************
  */
@@ -967,6 +967,8 @@ PLy_procedure_get(FunctionCallInfo fcinfo, Oid tgreloid)
                        elog(FATAL, "expected a PyCObject, didn't get one");
 
                proc = PyCObject_AsVoidPtr(plproc);
+               if (!proc)
+                       PLy_elog(ERROR, "PyCObject_AsVoidPtr() failed");
                if (proc->me != plproc)
                        elog(FATAL, "proc->me != plproc");
                /* did we find an up-to-date cache entry? */
@@ -1135,8 +1137,11 @@ PLy_procedure_create(FunctionCallInfo fcinfo, Oid tgreloid,
                PLy_procedure_compile(proc, procSource);
 
                pfree(procSource);
+               procSource = NULL;
 
                proc->me = PyCObject_FromVoidPtr(proc, NULL);
+               if (!proc->me)
+                       PLy_elog(ERROR, "PyCObject_FromVoidPtr() failed");
                PyDict_SetItemString(PLy_procedure_cache, key, proc->me);
        }
        PG_CATCH();