aboutsummaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_plpymodule.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-03-13 15:26:32 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-03-13 15:26:32 -0400
commit5cd72c7a7c7bd76ab028e1dc59d90a47750acebe (patch)
treec8200b31b4b15951a16a5cb0bb42f9805360574d /src/pl/plpython/plpy_plpymodule.c
parenta14fa84693659c4c4a17204406945b29fae3d9c4 (diff)
downloadpostgresql-5cd72c7a7c7bd76ab028e1dc59d90a47750acebe.tar.gz
postgresql-5cd72c7a7c7bd76ab028e1dc59d90a47750acebe.zip
Patch some corner-case bugs in pl/python.
Dave Malcolm of Red Hat is working on a static code analysis tool for Python-related C code. It reported a number of problems in plpython, most of which were failures to check for NULL results from object-creation functions, so would only be an issue in very-low-memory situations. Patch in HEAD and 9.1. We could go further back but it's not clear that these issues are important enough to justify the work. Jan UrbaƄski
Diffstat (limited to 'src/pl/plpython/plpy_plpymodule.c')
-rw-r--r--src/pl/plpython/plpy_plpymodule.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/pl/plpython/plpy_plpymodule.c b/src/pl/plpython/plpy_plpymodule.c
index d2d0a2a2323..01caa0a3236 100644
--- a/src/pl/plpython/plpy_plpymodule.c
+++ b/src/pl/plpython/plpy_plpymodule.c
@@ -173,9 +173,11 @@ PLy_init_plpy(void)
main_mod = PyImport_AddModule("__main__");
main_dict = PyModule_GetDict(main_mod);
plpy_mod = PyImport_AddModule("plpy");
+ if (plpy_mod == NULL)
+ PLy_elog(ERROR, "could not initialize plpy");
PyDict_SetItemString(main_dict, "plpy", plpy_mod);
if (PyErr_Occurred())
- elog(ERROR, "could not initialize plpy");
+ PLy_elog(ERROR, "could not initialize plpy");
}
static void
@@ -208,6 +210,11 @@ PLy_add_exceptions(PyObject *plpy)
PLy_exc_fatal = PyErr_NewException("plpy.Fatal", NULL, NULL);
PLy_exc_spi_error = PyErr_NewException("plpy.SPIError", NULL, NULL);
+ if (PLy_exc_error == NULL ||
+ PLy_exc_fatal == NULL ||
+ PLy_exc_spi_error == NULL)
+ PLy_elog(ERROR, "could not create the base SPI exceptions");
+
Py_INCREF(PLy_exc_error);
PyModule_AddObject(plpy, "Error", PLy_exc_error);
Py_INCREF(PLy_exc_fatal);
@@ -241,7 +248,13 @@ PLy_generate_spi_exceptions(PyObject *mod, PyObject *base)
PyObject *sqlstate;
PyObject *dict = PyDict_New();
+ if (dict == NULL)
+ PLy_elog(ERROR, "could not generate SPI exceptions");
+
sqlstate = PyString_FromString(unpack_sql_state(exception_map[i].sqlstate));
+ if (sqlstate == NULL)
+ PLy_elog(ERROR, "could not generate SPI exceptions");
+
PyDict_SetItemString(dict, "sqlstate", sqlstate);
Py_DECREF(sqlstate);
exc = PyErr_NewException(exception_map[i].name, base, dict);
@@ -370,7 +383,8 @@ PLy_output(volatile int level, PyObject *self, PyObject *args)
*/
PyObject *o;
- PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o);
+ if (!PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o))
+ PLy_elog(ERROR, "could not unpack arguments in plpy.elog");
so = PyObject_Str(o);
}
else