Issue #23996: Avoid a crash when a delegated generator raises an unnormalized StopIteration exception. Patch by Stefan Behnel.

This commit is contained in:
Antoine Pitrou 2015-04-26 18:48:16 +02:00
commit 7503509f19
2 changed files with 25 additions and 5 deletions

View File

@ -10,6 +10,9 @@ Release date: 2015-04-24
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 #9951: Added a hex() method to bytes, bytearray, and memoryview. - Issue #9951: Added a hex() method to bytes, bytearray, and memoryview.

View File

@ -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);
if (ev) {
/* exception will usually be normalised already */
if (Py_TYPE(ev) == (PyTypeObject *) et
|| 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(et);
Py_XDECREF(tb); Py_XDECREF(tb);
if (ev) {
value = ((PyStopIterationObject *)ev)->value;
Py_INCREF(value);
Py_DECREF(ev);
}
} else if (PyErr_Occurred()) { } else if (PyErr_Occurred()) {
return -1; return -1;
} }