Skip to content

Commit f3ab16c

Browse files
committed
MB-70730 Fix crash from progress bar getting win size
Previously we used `ioctl` directly to get the terminal size which was error-prone. We were passing a four character string as a buffer. The argument for `TIOCGWINSZ` should be four `unsigned short`s long and `unsigned short` is at least two bytes, so the call was overflowing a buffer. This didn't seem to cause a problem in practice, but recently the Python we ship was upgraded to 3.14 which catches these errors [1]. This caused a `None` to propagate and later accessed. We now use `termio.tcgetwinsize` to get the terminal size, and we add another `None` check. [1] python/cpython#132915 Change-Id: I6a6a636ca466edd3ef5f711b74002c36522e6044 Reviewed-on: https://review.couchbase.org/c/couchbase-cli/+/240979 Reviewed-by: Lubo Marinski <lubo.marinski@couchbase.com> Tested-by: Build Bot <build@couchbase.com> Well-Formed: Restriction Checker
1 parent 82f338b commit f3ab16c

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

pbar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def get_terminal_width():
6565
def ioctl_gwinsz(fd):
6666
"""Gets the windows size for a given file descriptor"""
6767
try:
68-
return struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
68+
return termios.tcgetwinsize(fd)
6969
except BaseException:
7070
return None
7171

@@ -78,6 +78,9 @@ def ioctl_gwinsz(fd):
7878
except BaseException:
7979
return None, None, None, None
8080

81+
if window_size is None:
82+
return None, None, None, None
83+
8184
return int(window_size[1]), int(window_size[0]), 0, 0
8285

8386
def bold(text):

0 commit comments

Comments
 (0)