Skip to content

Commit 9c51496

Browse files
committed
fix: Buffer overflow in bytes_to_read
Fix buffer overflow error in invoke/terminals.py::bytes_to_read by providing correctly sized int.
1 parent ba193d1 commit 9c51496

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

invoke/terminals.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def bytes_to_read(input_: IO) -> int:
243243
# it's not a tty but has a fileno, or vice versa; neither is typically
244244
# going to work re: ioctl().
245245
if not WINDOWS and isatty(input_) and has_fileno(input_):
246-
fionread = fcntl.ioctl(input_, termios.FIONREAD, b" ")
247-
return int(struct.unpack("h", fionread)[0])
246+
arg = bytes(bytearray(struct.calcsize("i")))
247+
fionread = fcntl.ioctl(input_, termios.FIONREAD, arg)
248+
return int(struct.unpack("i", fionread)[0])
248249
return 1

0 commit comments

Comments
 (0)