summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-12-13 19:51:56 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-12-13 19:51:56 (GMT)
commit733c8935f9dfd1be70c472649eb845ea22bbc878 (patch)
tree6febaf1b3d319c55fd8fc5b8789cc3ca4d8fab30 /Python/ceval.c
parent3095a4c2289b3155b2dc1bcf7284911dee0afe7d (diff)
downloadcpython-733c8935f9dfd1be70c472649eb845ea22bbc878.zip
cpython-733c8935f9dfd1be70c472649eb845ea22bbc878.tar.gz
cpython-733c8935f9dfd1be70c472649eb845ea22bbc878.tar.bz2
Fix for SF bug [ #492403 ] exec() segfaults on closure's func_code
Based on the patch from Danny Yoo. The fix is in exec_statement() in ceval.c. There are also changes to introduce use of PyCode_GetNumFree() in several places.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 29d7082..3e41b9a 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2094,7 +2094,7 @@ eval_frame(PyFrameObject *f)
int nfree;
v = POP(); /* code object */
x = PyFunction_New(v, f->f_globals);
- nfree = PyTuple_GET_SIZE(((PyCodeObject *)v)->co_freevars);
+ nfree = PyCode_GetNumFree((PyCodeObject *)v);
Py_DECREF(v);
/* XXX Maybe this should be a separate opcode? */
if (x != NULL && nfree > 0) {
@@ -3631,6 +3631,11 @@ exec_statement(PyFrameObject *f, PyObject *prog, PyObject *globals,
if (PyDict_GetItemString(globals, "__builtins__") == NULL)
PyDict_SetItemString(globals, "__builtins__", f->f_builtins);
if (PyCode_Check(prog)) {
+ if (PyCode_GetNumFree((PyCodeObject *)prog) > 0) {
+ PyErr_SetString(PyExc_TypeError,
+ "code object passed to exec may not contain free variables");
+ return -1;
+ }
v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
}
else if (PyFile_Check(prog)) {