mirror of
https://github.com/python/cpython.git
synced 2025-12-10 19:10:59 +00:00
Protect dir() against non-directory __dict__ attributes.
This commit is contained in:
parent
c0aab89d96
commit
dc8a108a36
1 changed files with 14 additions and 7 deletions
|
|
@ -78,20 +78,27 @@ builtin_dir(self, v)
|
||||||
object *d;
|
object *d;
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
d = getlocals();
|
d = getlocals();
|
||||||
|
INCREF(d);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!is_moduleobject(v)) {
|
d = getattr(v, "__dict__");
|
||||||
|
if (d == NULL) {
|
||||||
err_setstr(TypeError,
|
err_setstr(TypeError,
|
||||||
"dir() argument must be module or absent");
|
"dir() argument has no variable attributes");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
d = getmoduledict(v);
|
|
||||||
}
|
}
|
||||||
|
if (!is_dictobject(d)) { /* Assume it is None */
|
||||||
|
v = newlistobject(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
v = getdictkeys(d);
|
v = getdictkeys(d);
|
||||||
if (sortlist(v) != 0) {
|
if (sortlist(v) != 0) {
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
v = NULL;
|
v = NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
DECREF(d);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue