From ff0d636579f1128555bff72d1e5ae389cb476b6b Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 23 Dec 2024 17:12:43 +0100 Subject: [PATCH 1/7] Add missing `PyIter_Next` error check in `_asynciomodule.c` --- Modules/_asynciomodule.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 27c16364457336..42f1fb9eba4a92 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3623,6 +3623,14 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) Py_DECREF(item); } Py_DECREF(eager_iter); + + /* Check if loop ended because of exception in PyIter_Next */ + if (PyErr_Occurred()) { + Py_DECREF(tasks); + Py_DECREF(loop); + return NULL; + } + int err = 0; ASYNCIO_STATE_LOCK(state); TaskObj *first = &state->asyncio_tasks.first; @@ -3662,6 +3670,12 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) } Py_DECREF(scheduled_iter); Py_DECREF(loop); + + /* Check if loop ended because of exception in PyIter_Next */ + if (PyErr_Occurred()) { + return NULL; + } + return tasks; } From 761e8178ab529143fb44cbe48fb2cbea0adb7c92 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 23 Dec 2024 17:13:02 +0100 Subject: [PATCH 2/7] Add missing `PyIter_Next` error check in `_collectionsmodule.c` --- Modules/_collectionsmodule.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index aef04248c7e73c..6bdb23f00205b8 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1667,10 +1667,13 @@ deque_richcompare(PyObject *v, PyObject *w, int op) if (it2 == NULL) goto done; for (;;) { - x = PyIter_Next(it1); - if (x == NULL && PyErr_Occurred()) + if ((x = PyIter_Next(it1)) == NULL && PyErr_Occurred()) { goto done; - y = PyIter_Next(it2); + } + if ((y = PyIter_Next(it2)) == NULL && PyErr_Occurred()) { + Py_XDECREF(x); + goto done; + } if (x == NULL || y == NULL) break; b = PyObject_RichCompareBool(x, y, Py_EQ); From 4c9debae2c7bc5e2cfcab54fe74067aef809db1e Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 23 Dec 2024 17:13:20 +0100 Subject: [PATCH 3/7] Add missing `PyIter_Next` error check in `frameobject.c` --- Objects/frameobject.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 10fd3a982c36f4..2f1c9487ed2108 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -264,6 +264,11 @@ framelocalsproxy_merge(PyObject* self, PyObject* other) Py_DECREF(iter); + /* Check if loop ended because of exception in PyIter_Next */ + if (PyErr_Occurred()) { + return -1; + } + return 0; } From c6d319f66f7999a547f9c6e239f5fdf7464957d9 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Mon, 23 Dec 2024 17:13:36 +0100 Subject: [PATCH 4/7] Add missing `PyIter_Next` error check in `namespaceobject.c` --- Objects/namespaceobject.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index 5b7547103a2b3f..c450a51bbc3b99 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -141,6 +141,11 @@ namespace_repr(PyObject *ns) goto error; } + /* Check if loop ended because of exception in PyIter_Next */ + if (PyErr_Occurred()) { + goto error; + } + separator = PyUnicode_FromString(", "); if (separator == NULL) goto error; From 3b093fc34e4b6a8b00cd2b18590c69dd40391f3e Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Wed, 25 Dec 2024 10:33:46 +0100 Subject: [PATCH 5/7] Revert "Add missing `PyIter_Next` error check in `_collectionsmodule.c`" This reverts commit 761e8178ab529143fb44cbe48fb2cbea0adb7c92. --- Modules/_collectionsmodule.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 6bdb23f00205b8..aef04248c7e73c 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1667,13 +1667,10 @@ deque_richcompare(PyObject *v, PyObject *w, int op) if (it2 == NULL) goto done; for (;;) { - if ((x = PyIter_Next(it1)) == NULL && PyErr_Occurred()) { + x = PyIter_Next(it1); + if (x == NULL && PyErr_Occurred()) goto done; - } - if ((y = PyIter_Next(it2)) == NULL && PyErr_Occurred()) { - Py_XDECREF(x); - goto done; - } + y = PyIter_Next(it2); if (x == NULL || y == NULL) break; b = PyObject_RichCompareBool(x, y, Py_EQ); From ff6b7ee7af9d416175d6616522cd806ee25e5557 Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Wed, 25 Dec 2024 10:36:56 +0100 Subject: [PATCH 6/7] add missing `Py_DECREF` for tasks --- Modules/_asynciomodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 42f1fb9eba4a92..4c21a8e9869e7e 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3673,6 +3673,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) /* Check if loop ended because of exception in PyIter_Next */ if (PyErr_Occurred()) { + Py_DECREF(tasks); return NULL; } From 3aa46e79420298b551441bc9d4c2d13266d05e1d Mon Sep 17 00:00:00 2001 From: Yan Yanchii Date: Wed, 25 Dec 2024 11:09:32 +0100 Subject: [PATCH 7/7] remove comments --- Modules/_asynciomodule.c | 2 -- Objects/frameobject.c | 1 - Objects/namespaceobject.c | 1 - 3 files changed, 4 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 4c21a8e9869e7e..f212d8169cc177 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -3624,7 +3624,6 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) } Py_DECREF(eager_iter); - /* Check if loop ended because of exception in PyIter_Next */ if (PyErr_Occurred()) { Py_DECREF(tasks); Py_DECREF(loop); @@ -3671,7 +3670,6 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop) Py_DECREF(scheduled_iter); Py_DECREF(loop); - /* Check if loop ended because of exception in PyIter_Next */ if (PyErr_Occurred()) { Py_DECREF(tasks); return NULL; diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 2f1c9487ed2108..4f0040df4f3017 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -264,7 +264,6 @@ framelocalsproxy_merge(PyObject* self, PyObject* other) Py_DECREF(iter); - /* Check if loop ended because of exception in PyIter_Next */ if (PyErr_Occurred()) { return -1; } diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index c450a51bbc3b99..4ef3bd92f5a569 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -141,7 +141,6 @@ namespace_repr(PyObject *ns) goto error; } - /* Check if loop ended because of exception in PyIter_Next */ if (PyErr_Occurred()) { goto error; }