mirror of
https://github.com/cyrus-and/gdb-dashboard.git
synced 2025-12-05 01:00:13 +00:00
Merge pull request #342 from vlttnv/master
Fix buffer overflow in get_term_size() when using TIOCGWINSZ ioctl
This commit is contained in:
10
.gdbinit
10
.gdbinit
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user