summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-10-20 20:11:03 (GMT)
committerGuido van Rossum <guido@python.org>1991-10-20 20:11:03 (GMT)
commitdc8a108a36a55b480e302c556c773a2de17ec76a (patch)
tree7980fcc42de593d8e398f998f5db07cf2bbee5a4 /Python/bltinmodule.c
parentc0aab89d9694233cf962dc63395d4599acf35e37 (diff)
downloadcpython-dc8a108a36a55b480e302c556c773a2de17ec76a.zip
cpython-dc8a108a36a55b480e302c556c773a2de17ec76a.tar.gz
cpython-dc8a108a36a55b480e302c556c773a2de17ec76a.tar.bz2
Protect dir() against non-directory __dict__ attributes.
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 01cd5fa..8fac03c 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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;
}