summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-05-05 15:07:41 (GMT)
committerGitHub <noreply@github.com>2020-05-05 15:07:41 (GMT)
commitb0be6b3b94fbdf31b796adc19dc86a04a52b03e1 (patch)
tree72efb7493602da4318a06510379ceeaae5076bcd /Python
parent4e30ed3af06ae655f4cb8aad8cba21f341384250 (diff)
downloadcpython-b0be6b3b94fbdf31b796adc19dc86a04a52b03e1.zip
cpython-b0be6b3b94fbdf31b796adc19dc86a04a52b03e1.tar.gz
cpython-b0be6b3b94fbdf31b796adc19dc86a04a52b03e1.tar.bz2
bpo-29587: _PyErr_ChainExceptions() checks exception (GH-19902)
_PyErr_ChainExceptions() now ensures that the first parameter is an exception type, as done by _PyErr_SetObject(). * The following function now check PyExceptionInstance_Check() in an assertion using a new _PyBaseExceptionObject_cast() helper function: * PyException_GetTraceback(), PyException_SetTraceback() * PyException_GetCause(), PyException_SetCause() * PyException_GetContext(), PyException_SetContext() * PyExceptionClass_Name() now checks PyExceptionClass_Check() with an assertion. * Remove XXX comment and add gi_exc_state variable to _gen_throw(). * Remove comment from test_generators
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 9e53d05..f856a79 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -107,7 +107,8 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
if (exception != NULL &&
!PyExceptionClass_Check(exception)) {
_PyErr_Format(tstate, PyExc_SystemError,
- "exception %R not a BaseException subclass",
+ "_PyErr_SetObject: "
+ "exception %R is not a BaseException subclass",
exception);
return;
}
@@ -484,6 +485,15 @@ _PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb)
return;
PyThreadState *tstate = _PyThreadState_GET();
+
+ if (!PyExceptionClass_Check(exc)) {
+ _PyErr_Format(tstate, PyExc_SystemError,
+ "_PyErr_ChainExceptions: "
+ "exception %R is not a BaseException subclass",
+ exc);
+ return;
+ }
+
if (_PyErr_Occurred(tstate)) {
PyObject *exc2, *val2, *tb2;
_PyErr_Fetch(tstate, &exc2, &val2, &tb2);