diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-02-20 22:16:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-20 22:16:09 (GMT) |
commit | 022b44f2546c44183e4df7b67e3e64502fae9143 (patch) | |
tree | 64b46d13946bbf8704dd82d3d63a3297e96a6cfe /Python | |
parent | 4d3bc89a3f54c4f09756a9b644b3912bf54191a7 (diff) | |
download | cpython-022b44f2546c44183e4df7b67e3e64502fae9143.zip cpython-022b44f2546c44183e4df7b67e3e64502fae9143.tar.gz cpython-022b44f2546c44183e4df7b67e3e64502fae9143.tar.bz2 |
gh-102056: Fix a few bugs in error handling of exception printing code (#102078)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index ce993ea..34a44dd 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1246,8 +1246,7 @@ print_chained(struct exception_print_context* ctx, PyObject *value, const char * message, const char *tag) { PyObject *f = ctx->file; - - if (_Py_EnterRecursiveCall(" in print_chained") < 0) { + if (_Py_EnterRecursiveCall(" in print_chained")) { return -1; } bool need_close = ctx->need_close; @@ -1374,7 +1373,9 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value) if (ctx->exception_group_depth == 0) { ctx->exception_group_depth += 1; } - print_exception(ctx, value); + if (print_exception(ctx, value) < 0) { + return -1; + } PyObject *excs = ((PyBaseExceptionGroupObject *)value)->excs; assert(excs && PyTuple_Check(excs)); @@ -1424,7 +1425,7 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value) PyObject *exc = PyTuple_GET_ITEM(excs, i); if (!truncated) { - if (_Py_EnterRecursiveCall(" in print_exception_group") != 0) { + if (_Py_EnterRecursiveCall(" in print_exception_group")) { return -1; } int res = print_exception_recursive(ctx, exc); @@ -1477,22 +1478,30 @@ print_exception_group(struct exception_print_context *ctx, PyObject *value) static int print_exception_recursive(struct exception_print_context *ctx, PyObject *value) { + if (_Py_EnterRecursiveCall(" in print_exception_recursive")) { + return -1; + } if (ctx->seen != NULL) { /* Exception chaining */ if (print_exception_cause_and_context(ctx, value) < 0) { - return -1; + goto error; } } if (!_PyBaseExceptionGroup_Check(value)) { if (print_exception(ctx, value) < 0) { - return -1; + goto error; } } else if (print_exception_group(ctx, value) < 0) { - return -1; + goto error; } assert(!PyErr_Occurred()); + + _Py_LeaveRecursiveCall(); return 0; +error: + _Py_LeaveRecursiveCall(); + return -1; } #define PyErr_MAX_GROUP_WIDTH 15 |