Merge pull request #342 from vlttnv/master

Fix buffer overflow in get_term_size() when using TIOCGWINSZ ioctl
This commit is contained in:
Andrea Cardaci
2025-11-06 17:13:11 +01:00
committed by GitHub

View File

@@ -612,11 +612,13 @@ class Dashboard(gdb.Command):
else:
import termios
import fcntl
# first 2 shorts (4 byte) of struct winsize
raw = fcntl.ioctl(fd, termios.TIOCGWINSZ, ' ' * 4)
height, width = struct.unpack('hh', raw)
# first 2 shorts of struct winsize
winsize_format = 'hhhh'
buffer = b'\x00' * struct.calcsize(winsize_format)
buffer = fcntl.ioctl(fd, termios.TIOCGWINSZ, buffer)
height, width, _, _ = struct.unpack(winsize_format, buffer)
return int(width), int(height)
except (ImportError, OSError):
except (ImportError, OSError, SystemError):
# this happens when no curses library is found on windows or when
# the terminal is not properly configured
return 80, 24 # hardcoded fallback value