[Python-checkins] [2.7] bpo-22851: Fix a segfault when accessing generator.gi_frame.f_restricted. (GH-9348)
Serhiy Storchaka
webhook-mailer at python.org
Sat Oct 13 05:25:12 EDT 2018
https://github.com/python/cpython/commit/68ddb59417ee0b0dedf5c8b66a304138c9ce0a63
commit: 68ddb59417ee0b0dedf5c8b66a304138c9ce0a63
branch: 2.7
author: Zackery Spytz <zspytz at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2018-10-13T12:25:05+03:00
summary:
[2.7] bpo-22851: Fix a segfault when accessing generator.gi_frame.f_restricted. (GH-9348)
Frame's field f_tstate is NULL when the generator is exhausted.
files:
A Misc/NEWS.d/next/Core and Builtins/2018-09-17-04-41-42.bpo-22851.0hsJPh.rst
M Include/frameobject.h
M Lib/test/test_generators.py
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 843908159ddb..34603794c655 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -56,7 +56,7 @@ PyAPI_DATA(PyTypeObject) PyFrame_Type;
#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type)
#define PyFrame_IsRestricted(f) \
- ((f)->f_builtins != (f)->f_tstate->interp->builtins)
+ ((f)->f_tstate && (f)->f_builtins != (f)->f_tstate->interp->builtins)
PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *,
PyObject *, PyObject *);
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index 0f7bf19abb8c..10285f67a2c6 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -1877,6 +1877,16 @@ def printsolution(self, x):
"""
+crash_test = """
+>>> def foo(): yield
+>>> gen = foo()
+>>> gen.next()
+>>> print gen.gi_frame.f_restricted # This would segfault.
+False
+
+"""
+
+
__test__ = {"tut": tutorial_tests,
"pep": pep_tests,
"email": email_tests,
@@ -1886,6 +1896,7 @@ def printsolution(self, x):
"weakref": weakref_tests,
"coroutine": coroutine_tests,
"refleaks": refleaks_tests,
+ "crash": crash_test,
}
# Magic test name that regrtest.py invokes *after* importing this module.
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-09-17-04-41-42.bpo-22851.0hsJPh.rst b/Misc/NEWS.d/next/Core and Builtins/2018-09-17-04-41-42.bpo-22851.0hsJPh.rst
new file mode 100644
index 000000000000..c5f524940085
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-09-17-04-41-42.bpo-22851.0hsJPh.rst
@@ -0,0 +1,2 @@
+Fix a segfault when accessing ``generator.gi_frame.f_restricted`` when the
+generator is exhausted. Patch by Zackery Spytz.
More information about the Python-checkins
mailing list