]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Protect dir() against non-directory __dict__ attributes.
authorGuido van Rossum <guido@python.org>
Sun, 20 Oct 1991 20:11:03 +0000 (20:11 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 20 Oct 1991 20:11:03 +0000 (20:11 +0000)
Python/bltinmodule.c

index 01cd5fac33961a766d8ec3f4ab3ebc798b4640a5..8fac03c5988052987c4cefe13217d784206edf2d 100644 (file)
@@ -78,20 +78,27 @@ builtin_dir(self, v)
        object *d;
        if (v == NULL) {
                d = getlocals();
+               INCREF(d);
        }
        else {
-               if (!is_moduleobject(v)) {
+               d = getattr(v, "__dict__");
+               if (d == NULL) {
                        err_setstr(TypeError,
-                               "dir() argument must be module or absent");
+                               "dir() argument has no variable attributes");
                        return NULL;
                }
-               d = getmoduledict(v);
        }
-       v = getdictkeys(d);
-       if (sortlist(v) != 0) {
-               DECREF(v);
-               v = NULL;
+       if (!is_dictobject(d)) { /* Assume it is None */
+               v = newlistobject(0);
        }
+       else {
+               v = getdictkeys(d);
+               if (sortlist(v) != 0) {
+                       DECREF(v);
+                       v = NULL;
+               }
+       }
+       DECREF(d);
        return v;
 }