]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport r51245 | neal.norwitz]
authorAndrew M. Kuchling <amk@amk.ca>
Wed, 4 Oct 2006 13:17:42 +0000 (13:17 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Wed, 4 Oct 2006 13:17:42 +0000 (13:17 +0000)
Move/copy assert for tstate != NULL before first use.
Verify that PyEval_Get{Globals,Locals} returned valid pointers.

Klocwork 231-232

Python/ceval.c

index d270c926e02c5531e8571a91a06fa8940073ed78..a6201b44ce772365c3119a9400be7c65f783bb60 100644 (file)
@@ -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;