mirror of
https://github.com/python/cpython.git
synced 2025-09-11 11:17:16 +00:00
#2542: now that issubclass() may call arbitrary code,
make sure that PyErr_ExceptionMatches returns 0 when an exception occurs there.
This commit is contained in:
parent
b8827c00b8
commit
246daedd11
3 changed files with 49 additions and 4 deletions
|
@ -106,9 +106,18 @@ PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
|
|||
err = PyExceptionInstance_Class(err);
|
||||
|
||||
if (PyExceptionClass_Check(err) && PyExceptionClass_Check(exc)) {
|
||||
/* problems here!? not sure PyObject_IsSubclass expects to
|
||||
be called with an exception pending... */
|
||||
return PyObject_IsSubclass(err, exc);
|
||||
int res = 0;
|
||||
PyObject *exception, *value, *tb;
|
||||
PyErr_Fetch(&exception, &value, &tb);
|
||||
res = PyObject_IsSubclass(err, exc);
|
||||
/* This function must not fail, so print the error here */
|
||||
if (res == -1) {
|
||||
PyErr_WriteUnraisable(err);
|
||||
/* issubclass did not succeed */
|
||||
res = 0;
|
||||
}
|
||||
PyErr_Restore(exception, value, tb);
|
||||
return res;
|
||||
}
|
||||
|
||||
return err == exc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue