Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-128198: Add missing error checks for usages of PyIter_Next #128199

Merged
merged 7 commits into from
Dec 25, 2024
14 changes: 14 additions & 0 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
picnixz marked this conversation as resolved.
Show resolved Hide resolved
if (PyErr_Occurred()) {
Py_DECREF(tasks);
Py_DECREF(loop);
return NULL;
}

int err = 0;
ASYNCIO_STATE_LOCK(state);
TaskObj *first = &state->asyncio_tasks.first;
Expand Down Expand Up @@ -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;
picnixz marked this conversation as resolved.
Show resolved Hide resolved
}

return tasks;
}

Expand Down
9 changes: 6 additions & 3 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
picnixz marked this conversation as resolved.
Show resolved Hide resolved
goto done;
y = PyIter_Next(it2);
}
if ((y = PyIter_Next(it2)) == NULL && PyErr_Occurred()) {
Py_XDECREF(x);
picnixz marked this conversation as resolved.
Show resolved Hide resolved
goto done;
}
if (x == NULL || y == NULL)
break;
b = PyObject_RichCompareBool(x, y, Py_EQ);
Expand Down
5 changes: 5 additions & 0 deletions Objects/frameobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions Objects/namespaceobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading