Mercurial > cpython-lru_cache-weakref
diff Objects/object.c @ 23437:82460fda4f76 2.2
Backport from 2.3:
Jim Fulton reported a segfault in dir(). A heavily proxied object
returned a proxy for __class__ whose __bases__ was also a proxy. The
merge_class_dict() helper for dir() assumed incorrectly that __bases__
would always be a tuple and used the in-line tuple API on the proxy.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 13 May 2002 18:30:40 +0000 |
| parents | db040938dc66 |
| children | 3f196b4dc4c1 |
line wrap: on
line diff
--- a/Objects/object.c Mon May 13 09:11:44 2002 +0000 +++ b/Objects/object.c Mon May 13 18:30:40 2002 +0000 @@ -1507,14 +1507,22 @@ if (bases == NULL) PyErr_Clear(); else { + /* We have no guarantee that bases is a real tuple */ int i, n; - assert(PyTuple_Check(bases)); - n = PyTuple_GET_SIZE(bases); - for (i = 0; i < n; i++) { - PyObject *base = PyTuple_GET_ITEM(bases, i); - if (merge_class_dict(dict, base) < 0) { - Py_DECREF(bases); - return -1; + n = PySequence_Size(bases); /* This better be right */ + if (n < 0) + PyErr_Clear(); + else { + for (i = 0; i < n; i++) { + PyObject *base = PySequence_GetItem(bases, i); + if (base == NULL) { + Py_DECREF(bases); + return -1; + } + if (merge_class_dict(dict, base) < 0) { + Py_DECREF(bases); + return -1; + } } } Py_DECREF(bases);
