Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,16 @@ def test_future_disallow_multiple_initialization(self):
with self.assertRaises(RuntimeError, msg="is already initialized"):
f.__init__(loop=self.loop)

def test_futureiter_send_after_throw_no_crash(self):
fut = self._new_future(loop=self.loop)
it = fut.__await__()
next(it)
with self.assertRaises(RuntimeError):
it.throw(RuntimeError)
with self.assertRaises(StopIteration):
it.send(None)


@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
class CFutureTests(BaseFutureTests, test_utils.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a NULL pointer dereference in asyncio.Future iterator when send() is
called after throw() or close(), which previously could cause a crash.
5 changes: 5 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,11 @@ FutureIter_am_send(PyObject *op,
PyObject **result)
{
futureiterobject *it = (futureiterobject*)op;
if (it->future == NULL) {
PyErr_SetNone(PyExc_StopIteration);
*result = NULL;
return PYGEN_ERROR;
}
/* arg is unused, see the comment on FutureIter_send for clarification */
PySendResult res;
Py_BEGIN_CRITICAL_SECTION(it->future);
Expand Down