Fix for SF bug [ #443866 ] Evaluating func_code causing core dump

If the code object has free variables, raise TypeError.
This commit is contained in:
Jeremy Hylton 2001-07-30 21:50:55 +00:00
parent e3c37d660f
commit 15c1c4f6d2
1 changed files with 7 additions and 1 deletions

View File

@ -800,8 +800,14 @@ builtin_eval(PyObject *self, PyObject *args)
PyEval_GetBuiltins()) != 0)
return NULL;
}
if (PyCode_Check(cmd))
if (PyCode_Check(cmd)) {
if (PyTuple_GET_SIZE(((PyCodeObject *)cmd)->co_freevars) > 0) {
PyErr_SetString(PyExc_TypeError,
"code object passed to eval() may not contain free variables");
return NULL;
}
return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
}
if (!PyString_Check(cmd) &&
!PyUnicode_Check(cmd)) {
PyErr_SetString(PyExc_TypeError,