bpo-45262, asyncio: Fix cache of the running loop holder (GH-28796)

Prevent use-after-free of running loop holder via cache.
This commit is contained in:
Matthias Reichl 2021-10-08 00:46:49 +02:00 committed by GitHub
parent 0219017df7
commit 392a898353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 0 deletions

View File

@ -0,0 +1 @@
Prevent use-after-free in asyncio. Make sure the cached running loop holder gets cleared on dealloc to prevent use-after-free in get_running_loop

View File

@ -3239,6 +3239,9 @@ new_running_loop_holder(PyObject *loop)
static void
PyRunningLoopHolder_tp_dealloc(PyRunningLoopHolder *rl)
{
if (cached_running_holder == (PyObject *)rl) {
cached_running_holder = NULL;
}
Py_CLEAR(rl->rl_loop);
PyObject_Free(rl);
}