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

Add missing error checks for usages of PyIter_Next #128198

Open
WolframAlph opened this issue Dec 23, 2024 · 0 comments
Open

Add missing error checks for usages of PyIter_Next #128198

WolframAlph opened this issue Dec 23, 2024 · 0 comments
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@WolframAlph
Copy link
Contributor

WolframAlph commented Dec 23, 2024

Bug report

Bug description:

Not all usages of PyIter_Next in the codebase comply with specified behavior:

cpython/Objects/abstract.c

Lines 2905 to 2919 in 180d417

/* Return next item.
*
* If an error occurs, return NULL. PyErr_Occurred() will be true.
* If the iteration terminates normally, return NULL and clear the
* PyExc_StopIteration exception (if it was set). PyErr_Occurred()
* will be false.
* Else return the next object. PyErr_Occurred() will be false.
*/
PyObject *
PyIter_Next(PyObject *iter)
{
PyObject *item;
(void)iternext(iter, &item);
return item;
}
.
One example would be:
while ((key = PyIter_Next(iter)) != NULL) {
value = PyObject_GetItem(other, key);
if (value == NULL) {
Py_DECREF(key);
Py_DECREF(iter);
return -1;
}
if (framelocalsproxy_setitem(self, key, value) < 0) {
Py_DECREF(key);
Py_DECREF(value);
Py_DECREF(iter);
return -1;
}
Py_DECREF(key);
Py_DECREF(value);
}
Py_DECREF(iter);
return 0;
}

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

@WolframAlph WolframAlph added the type-bug An unexpected behavior, bug, or error label Dec 23, 2024
@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.13 bugs and security fixes 3.14 new features, bugs and security fixes 3.12 bugs and security fixes labels Dec 24, 2024
@picnixz picnixz changed the title Add missing error checks for PyIter_Next Add missing error checks for usages of PyIter_Next Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants