[3.11] gh-99184: Bypass instance attribute access in repr of weakref.ref (GH-99244) (#103789)

gh-99184: Bypass instance attribute access in `repr` of `weakref.ref` (GH-99244)
(cherry picked from commit 58b6be3791)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2023-04-24 12:58:55 -07:00 committed by GitHub
parent a8489f7f26
commit c8de883bcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View file

@ -170,10 +170,7 @@ weakref_repr(PyWeakReference *self)
}
Py_INCREF(obj);
if (_PyObject_LookupAttr(obj, &_Py_ID(__name__), &name) < 0) {
Py_DECREF(obj);
return NULL;
}
name = _PyObject_LookupSpecial(obj, &_Py_ID(__name__));
if (name == NULL || !PyUnicode_Check(name)) {
repr = PyUnicode_FromFormat(
"<weakref at %p; to '%s' at %p>",