Skip to content

Commit

Permalink
bpo-28963: Fix out of bound iteration in asyncio.Future.remove_done_c…
Browse files Browse the repository at this point in the history
…allback/C (#408)
  • Loading branch information
1st1 committed Mar 3, 2017
1 parent 2f15645 commit 84af903
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Expand Up @@ -569,6 +569,35 @@ def test_remove_done_callback(self):
self.assertEqual(bag, [2])
self.assertEqual(f.result(), 'foo')

def test_remove_done_callbacks_list_mutation(self):
# see http://bugs.python.org/issue28963 for details

fut = self._new_future()
fut.add_done_callback(str)

for _ in range(63):
fut.add_done_callback(id)

class evil:
def __eq__(self, other):
fut.remove_done_callback(id)
return False

fut.remove_done_callback(evil())

def test_schedule_callbacks_list_mutation(self):
# see http://bugs.python.org/issue28963 for details

def mut(f):
f.remove_done_callback(str)

fut = self._new_future()
fut.add_done_callback(mut)
fut.add_done_callback(str)
fut.add_done_callback(str)
fut.set_result(1)
test_utils.run_briefly(self.loop)


@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Expand Up @@ -259,6 +259,9 @@ Extension Modules
Library
-------

- bpo-28963: Fix out of bound iteration in asyncio.Future.remove_done_callback
implemented in C.

- bpo-29704: asyncio.subprocess.SubprocessStreamProtocol no longer closes before
all pipes are closed.

Expand Down
2 changes: 1 addition & 1 deletion Modules/_asynciomodule.c
Expand Up @@ -522,7 +522,7 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn)
return NULL;
}

for (i = 0; i < len; i++) {
for (i = 0; i < PyList_GET_SIZE(self->fut_callbacks); i++) {
int ret;
PyObject *item = PyList_GET_ITEM(self->fut_callbacks, i);

Expand Down

0 comments on commit 84af903

Please sign in to comment.