From 3b93688db6abe8a1b3a975ad8a2e770af056c9aa Mon Sep 17 00:00:00 2001 From: "Andrew M. Kuchling" Date: Wed, 4 Oct 2006 13:17:42 +0000 Subject: [Backport r51245 | neal.norwitz] Move/copy assert for tstate != NULL before first use. Verify that PyEval_Get{Globals,Locals} returned valid pointers. Klocwork 231-232 --- Python/ceval.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index d270c926e0..a6201b44ce 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -2524,6 +2524,7 @@ PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals, return NULL; } + assert(tstate != NULL); assert(globals != NULL); f = PyFrame_New(tstate, co, globals, locals); if (f == NULL) @@ -3631,6 +3632,7 @@ fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk) PyFrame_New() that doesn't take locals, but does take builtins without sanity checking them. */ + assert(tstate != NULL); f = PyFrame_New(tstate, co, globals, NULL); if (f == NULL) return NULL; @@ -3643,7 +3645,6 @@ fast_function(PyObject *func, PyObject ***pp_stack, int n, int na, int nk) fastlocals[i] = *stack++; } retval = PyEval_EvalFrame(f); - assert(tstate != NULL); ++tstate->recursion_depth; Py_DECREF(f); --tstate->recursion_depth; @@ -4153,6 +4154,11 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals, locals = PyEval_GetLocals(); plain = 1; } + if (!globals || !locals) { + PyErr_SetString(PyExc_SystemError, + "globals and locals cannot be NULL"); + return -1; + } } else if (locals == Py_None) locals = globals; -- cgit v1.2.1