summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-12 13:15:14 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-12 13:15:14 (GMT)
commited3b838988ba656cdbb184fcb6589654c81ab276 (patch)
treeca1a6cfc2d0c5917dea015beac4a0c914d741c89 /Objects
parente32b4224d0e5a5a2faa7398211ad859e8a4cb0c8 (diff)
downloadcpython-ed3b838988ba656cdbb184fcb6589654c81ab276.zip
cpython-ed3b838988ba656cdbb184fcb6589654c81ab276.tar.gz
cpython-ed3b838988ba656cdbb184fcb6589654c81ab276.tar.bz2
Check the keys of the locals dict -- they need not be a list.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c
index e2d1b13..f4ae4f3 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1349,6 +1349,7 @@ merge_class_dict(PyObject* dict, PyObject* aclass)
static PyObject *
_dir_locals()
{
+ PyObject *names;
PyObject *locals = PyEval_GetLocals();
if (locals == NULL) {
@@ -1356,8 +1357,18 @@ _dir_locals()
return NULL;
}
+ names = PyMapping_Keys(locals);
+ if (!names)
+ return NULL;
+ if (!PyList_Check(names)) {
+ PyErr_Format(PyExc_TypeError,
+ "dir(): expected keys() of locals to be a list, "
+ "not '%.200s'", names->ob_type->tp_name);
+ Py_DECREF(names);
+ return NULL;
+ }
/* the locals don't need to be DECREF'd */
- return PyMapping_Keys(locals);
+ return names;
}
/* Helper for PyObject_Dir of type objects: returns __dict__ and __bases__.