summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-09-27 16:21:33 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2017-09-27 16:21:33 (GMT)
commit084f80b82c564c8a3cef26fc6e56da188a379be2 (patch)
tree8cb66ebd9f41cb413dee48731c61a1fd37df8110 /Python/bltinmodule.c
parentfdcf3e9629201ef725af629d99e02215a2d657c8 (diff)
downloadcpython-084f80b82c564c8a3cef26fc6e56da188a379be2.zip
cpython-084f80b82c564c8a3cef26fc6e56da188a379be2.tar.gz
cpython-084f80b82c564c8a3cef26fc6e56da188a379be2.tar.bz2
[3.6] bpo-31588: Validate return value of __prepare__() methods (GH-3790)
Class execution requires that __prepare__() methods return a proper execution namespace. Check for that immediately after calling __prepare__(), rather than passing it through to the code execution machinery and potentially triggering SystemError (in debug builds) or a cryptic TypeError (in release builds). Patch by Oren Milman. (cherry picked from commit 5837d0418f47933b2e3c139bdee8a79c248a943c)
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 911e2ba..1960a09 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -167,6 +167,13 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
Py_DECREF(bases);
return NULL;
}
+ if (!PyMapping_Check(ns)) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s.__prepare__() must return a mapping, not %.200s",
+ isclass ? ((PyTypeObject *)meta)->tp_name : "<metaclass>",
+ Py_TYPE(ns)->tp_name);
+ goto error;
+ }
cell = PyEval_EvalCodeEx(PyFunction_GET_CODE(func), PyFunction_GET_GLOBALS(func), ns,
NULL, 0, NULL, 0, NULL, 0, NULL,
PyFunction_GET_CLOSURE(func));