]> granicus.if.org Git - python/commitdiff
Check the keys of the locals dict -- they need not be a list.
authorGeorg Brandl <georg@python.org>
Mon, 12 Mar 2007 13:15:14 +0000 (13:15 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 12 Mar 2007 13:15:14 +0000 (13:15 +0000)
Objects/object.c

index e2d1b134fb0dc9d154d5d2380bf6f8fb131a770e..f4ae4f3dfb943e4dcbac2a112d206585af392fcf 100644 (file)
@@ -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__.