Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de821be

Browse files
committed
Issue #23571: PyErr_FormatV() and PyErr_SetObject() now always clear the
current exception because they can run arbitrary Python code and so no exception must be set.
1 parent 91afbb6 commit de821be

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

Python/errors.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ PyErr_SetObject(PyObject *exception, PyObject *value)
7474
if (value == NULL || !PyExceptionInstance_Check(value)) {
7575
/* We must normalize the value right now */
7676
PyObject *args, *fixed_value;
77-
#ifdef Py_DEBUG
78-
/* in debug mode, PyEval_EvalFrameEx() fails with an assertion
79-
error if an exception is set when it is called */
77+
78+
/* Issue #23571: PyEval_CallObject() must not be called with an
79+
exception set */
8080
PyErr_Clear();
81-
#endif
81+
8282
if (value == NULL || value == Py_None)
8383
args = PyTuple_New(0);
8484
else if (PyTuple_Check(value)) {
@@ -778,13 +778,12 @@ PyErr_FormatV(PyObject *exception, const char *format, va_list vargs)
778778
{
779779
PyObject* string;
780780

781-
#ifdef Py_DEBUG
782-
/* in debug mode, PyEval_EvalFrameEx() fails with an assertion error
783-
if an exception is set when it is called */
781+
/* Issue #23571: PyUnicode_FromFormatV() must not be called with an
782+
exception set, it calls arbitrary Python code like PyObject_Repr() */
784783
PyErr_Clear();
785-
#endif
786784

787785
string = PyUnicode_FromFormatV(format, vargs);
786+
788787
PyErr_SetObject(exception, string);
789788
Py_XDECREF(string);
790789
return NULL;

0 commit comments

Comments
 (0)