diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-18 16:10:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-18 16:10:55 (GMT) |
commit | 82ab9e6b7938484724a19e293a640d956111a012 (patch) | |
tree | 71e603440c9c07a233dda45a3e816624def46d73 /Objects/exceptions.c | |
parent | bbac9a8bcc4d7c0692e8b4f62a955f7ca107b496 (diff) | |
download | cpython-82ab9e6b7938484724a19e293a640d956111a012.zip cpython-82ab9e6b7938484724a19e293a640d956111a012.tar.gz cpython-82ab9e6b7938484724a19e293a640d956111a012.tar.bz2 |
gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException (GH-99572)
(cherry picked from commit c8c6113398ee9a7867fe9b08bc539cceb61e2aaa)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 01522aa..4fba9b0 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -774,7 +774,19 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds) } } else { - /* Do nothing - we don't interfere with subclasses */ + /* user-defined subclass */ + if (nested_base_exceptions) { + int nonbase = PyObject_IsSubclass((PyObject*)cls, PyExc_Exception); + if (nonbase == -1) { + goto error; + } + else if (nonbase == 1) { + PyErr_Format(PyExc_TypeError, + "Cannot nest BaseExceptions in '%.200s'", + cls->tp_name); + goto error; + } + } } if (!cls) { |