8000 gh-125038: PyIter_Checks are added for some FOR_ITER bytecodes · efimov-mikhail/cpython@523f765 · GitHub
[go: up one dir, main page]

Skip to content

Commit 523f765

Browse files
pythongh-125038: PyIter_Checks are added for some FOR_ITER bytecodes
SIGSEGV on generators in case of gi_frame.f_locals is fixed. This applies to _FOR_ITER bytecode. Similar checks are added to _FOR_ITER_TIER_TWO and INSTRUMENTED_FOR_ITER bytecode implementations.
1 parent c5df1cb commit 523f765

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

Python/bytecodes.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,10 @@ dummy_func(
28062806
replaced op(_FOR_ITER, (iter -- iter, next)) {
28072807
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
28082808
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
2809-
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
2809+
PyObject *next_o = NULL;
2810+
if (PyIter_Check(iter_o)) {
2811+
next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
2812+
}
28102813
if (next_o == NULL) {
28112814
if (_PyErr_Occurred(tstate)) {
28122815
int matches = _PyErr_ExceptionMatches(tstate, PyExc_StopIteration);
@@ -2832,7 +2835,10 @@ dummy_func(
28322835
op(_FOR_ITER_TIER_TWO, (iter -- iter, next)) {
28332836
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */
28342837
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter);
2835-
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
2838+
PyObject *next_o = NULL;
2839+
if (PyIter_Check(iter_o)) {
2840+
next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o);
2841+
}
28362842
if (next_o == NULL) {
28372843
if (_PyErr_Occurred(tstate)) {
28382844
int matches = _PyErr_ExceptionMatches(tstate, PyExc_StopIteration);
@@ -2856,7 +2862,10 @@ dummy_func(
28562862
_Py_CODEUNIT *target;
28572863
_PyStackRef iter_stackref = TOP();
28582864
PyObject *iter = PyStackRef_AsPyObjectBorrow(iter_stackref);
2859-
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
2865+
PyObject *next = NULL;
2866+
if (PyIter_Check(iter)) {
2867+
next = (*Py_TYPE(iter)->tp_iternext)(iter);
2868+
}
28602869
if (next != NULL) {
28612870
PUSH(PyStackRef_FromPyObjectSteal(next));
28622871
target = next_instr;

Python/executor_cases.c.h

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 12 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0