]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126405: fix use-after-free in `_asyncio.Future.remove_done_callback` (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 12 Nov 2024 13:04:27 +0000 (14:04 +0100)
committerGitHub <noreply@github.com>
Tue, 12 Nov 2024 13:04:27 +0000 (13:04 +0000)
gh-126405: fix use-after-free in `_asyncio.Future.remove_done_callback` (GH-126733)
(cherry picked from commit 37c57dfad12744608091653fd753a1f770e2479b)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Modules/_asynciomodule.c

index 79896c6b9fdd925de8faf0702811ca19916d2320..7e2fe28423399fb3061696dd5553dbff24f0c350 100644 (file)
@@ -994,8 +994,10 @@ _asyncio_Future_remove_done_callback_impl(FutureObj *self, PyTypeObject *cls,
 
     if (len == 1) {
         PyObject *cb_tup = PyList_GET_ITEM(self->fut_callbacks, 0);
+        Py_INCREF(cb_tup);
         int cmp = PyObject_RichCompareBool(
             PyTuple_GET_ITEM(cb_tup, 0), fn, Py_EQ);
+        Py_DECREF(cb_tup);
         if (cmp == -1) {
             return NULL;
         }