Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ptyprocess/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def _setecho(fd, state):
raise

def _setwinsize(fd, rows, cols):
if not (0 <= rows <= 65535 and 0 <= cols <= 65535):
raise ValueError(
"rows ({}) and cols ({}) must be between 0 and 65535".format(rows, cols)
)
# Some very old platforms have a bug that causes the value for
# termios.TIOCSWINSZ to be truncated. There was a hack here to work
# around this, but it caused problems with newer platforms so has been
Expand Down Expand Up @@ -813,6 +817,8 @@ def setwinsize(self, rows, cols):
TTY-aware applications like vi or curses -- applications that respond to
the SIGWINCH signal.
"""
if self.closed or self.fd < 0:
raise PtyProcessError("Cannot set window size on a closed PtyProcess.")
return _setwinsize(self.fd, rows, cols)


Expand Down
12 changes: 12 additions & 0 deletions tests/test_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,15 @@ def test_pass_fds(self):

with open(temp_file_name, 'r') as temp_file_r:
assert temp_file_r.read() == 'hello'

def test_setwinsize_bounds(self):
p = PtyProcess.spawn(['true'])
p.setwinsize(24, 80)
self.assertEqual(p.getwinsize(), (24, 80))
with self.assertRaises(ValueError):
p.setwinsize(-1, 80)
with self.assertRaises(ValueError):
p.setwinsize(24, 70000)
p.close()
with self.assertRaises(Exception):
p.setwinsize(24, 80)