bpo-41991: Remove _PyObject_HasAttrId (GH-22629)

It can silence arbitrary exceptions.
This commit is contained in:
Serhiy Storchaka 2020-10-10 22:23:42 +03:00 committed by GitHub
parent 02a1603f91
commit 98c4433a81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 22 deletions

View file

@ -311,21 +311,22 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
_Py_IDENTIFIER(__args__);
PyObject *qualname = NULL;
PyObject *module = NULL;
PyObject *tmp;
PyObject *r = NULL;
int err;
int has_origin = _PyObject_HasAttrId(p, &PyId___origin__);
if (has_origin < 0) {
if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
goto exit;
}
if (has_origin) {
int has_args = _PyObject_HasAttrId(p, &PyId___args__);
if (has_args < 0) {
if (tmp) {
Py_DECREF(tmp);
if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
goto exit;
}
if (has_args) {
if (tmp) {
// It looks like a GenericAlias
Py_DECREF(tmp);
goto use_repr;
}
}