mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)
The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
This commit is contained in:
parent
2dad1e08ec
commit
0ef4ffeefd
23 changed files with 513 additions and 213 deletions
|
|
@ -1710,6 +1710,29 @@ class BuiltinTest(ComplexesAreIdenticalMixin, unittest.TestCase):
|
|||
sys.stdout = savestdout
|
||||
fp.close()
|
||||
|
||||
def test_input_gh130163(self):
|
||||
class X(io.StringIO):
|
||||
def __getattribute__(self, name):
|
||||
nonlocal patch
|
||||
if patch:
|
||||
patch = False
|
||||
sys.stdout = X()
|
||||
sys.stderr = X()
|
||||
sys.stdin = X('input\n')
|
||||
support.gc_collect()
|
||||
return io.StringIO.__getattribute__(self, name)
|
||||
|
||||
with (support.swap_attr(sys, 'stdout', None),
|
||||
support.swap_attr(sys, 'stderr', None),
|
||||
support.swap_attr(sys, 'stdin', None)):
|
||||
patch = False
|
||||
# the only references:
|
||||
sys.stdout = X()
|
||||
sys.stderr = X()
|
||||
sys.stdin = X('input\n')
|
||||
patch = True
|
||||
input() # should not crash
|
||||
|
||||
# test_int(): see test_int.py for tests of built-in function int().
|
||||
|
||||
def test_repr(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue