mirror of
https://github.com/python/cpython.git
synced 2025-11-01 02:38:53 +00:00
gh-128636: Fix crash in PyREPL when os.environ is overwritten with an invalid value (#128653)
This commit is contained in:
parent
2ed5ee9a50
commit
ba9a4b6215
3 changed files with 22 additions and 5 deletions
|
|
@ -449,10 +449,12 @@ class UnixConsole(Console):
|
|||
"""
|
||||
try:
|
||||
return int(os.environ["LINES"]), int(os.environ["COLUMNS"])
|
||||
except KeyError:
|
||||
height, width = struct.unpack(
|
||||
"hhhh", ioctl(self.input_fd, TIOCGWINSZ, b"\000" * 8)
|
||||
)[0:2]
|
||||
except (KeyError, TypeError, ValueError):
|
||||
try:
|
||||
size = ioctl(self.input_fd, TIOCGWINSZ, b"\000" * 8)
|
||||
except OSError:
|
||||
return 25, 80
|
||||
height, width = struct.unpack("hhhh", size)[0:2]
|
||||
if not height:
|
||||
return 25, 80
|
||||
return height, width
|
||||
|
|
@ -468,7 +470,7 @@ class UnixConsole(Console):
|
|||
"""
|
||||
try:
|
||||
return int(os.environ["LINES"]), int(os.environ["COLUMNS"])
|
||||
except KeyError:
|
||||
except (KeyError, TypeError, ValueError):
|
||||
return 25, 80
|
||||
|
||||
def forgetinput(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue