Commit 1339cae1 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #23996: Avoid a crash when a delegated generator raises an unnormalized...

Issue #23996: Avoid a crash when a delegated generator raises an unnormalized StopIteration exception.  Patch by Stefan Behnel.
parent ba14aa52
...@@ -10,6 +10,9 @@ Release date: tba ...@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #23996: Avoid a crash when a delegated generator raises an
unnormalized StopIteration exception. Patch by Stefan Behnel.
- Issue #24022: Fix tokenizer crash when processing undecodable source code. - Issue #24022: Fix tokenizer crash when processing undecodable source code.
- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted - Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
......
...@@ -396,13 +396,30 @@ _PyGen_FetchStopIterationValue(PyObject **pvalue) { ...@@ -396,13 +396,30 @@ _PyGen_FetchStopIterationValue(PyObject **pvalue) {
if (PyErr_ExceptionMatches(PyExc_StopIteration)) { if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
PyErr_Fetch(&et, &ev, &tb); PyErr_Fetch(&et, &ev, &tb);
Py_XDECREF(et);
Py_XDECREF(tb);
if (ev) { if (ev) {
value = ((PyStopIterationObject *)ev)->value; /* exception will usually be normalised already */
Py_INCREF(value); if (Py_TYPE(ev) == (PyTypeObject *) et
Py_DECREF(ev); || PyObject_IsInstance(ev, PyExc_StopIteration)) {
value = ((PyStopIterationObject *)ev)->value;
Py_INCREF(value);
Py_DECREF(ev);
} else if (et == PyExc_StopIteration) {
/* avoid normalisation and take ev as value */
value = ev;
} else {
/* normalisation required */
PyErr_NormalizeException(&et, &ev, &tb);
if (!PyObject_IsInstance(ev, PyExc_StopIteration)) {
PyErr_Restore(et, ev, tb);
return -1;
}
value = ((PyStopIterationObject *)ev)->value;
Py_INCREF(value);
Py_DECREF(ev);
}
} }
Py_XDECREF(et);
Py_XDECREF(tb);
} else if (PyErr_Occurred()) { } else if (PyErr_Occurred()) {
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment