Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15c1c4f

Browse files
committed
Fix for SF bug [ #443866 ] Evaluating func_code causing core dump
If the code object has free variables, raise TypeError.
1 parent e3c37d6 commit 15c1c4f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Python/bltinmodule.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,14 @@ builtin_eval(PyObject *self, PyObject *args)
800800
PyEval_GetBuiltins()) != 0)
801801
return NULL;
802802
}
803-
if (PyCode_Check(cmd))
803+
if (PyCode_Check(cmd)) {
804+
if (PyTuple_GET_SIZE(((PyCodeObject *)cmd)->co_freevars) > 0) {
805+
PyErr_SetString(PyExc_TypeError,
806+
"code object passed to eval() may not contain free variables");
807+
return NULL;
808+
}
804809
return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
810+
}
805811
if (!PyString_Check(cmd) &&
806812
!PyUnicode_Check(cmd)) {
807813
PyErr_SetString(PyExc_TypeError,

0 commit comments

Comments
 (0)