From 29630ac92e6303e8196aef2eb32092e1e36d5252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 2 Jun 2020 19:59:28 +0200 Subject: [PATCH] term: set an initial TIOCSWINSZ right after opening the pty Since foot is pretty aggressive about spawning the client early, it was possible for a fast client to read a 0x0 terminal size. Not all clients coped well. Closes #20. --- CHANGELOG.md | 2 ++ terminal.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5113e95..5aca097c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ * Selection of double-width characters. It is no longer possible to select half of a double-width character. * Draw hollow block cursor on top of character. +* Set an initial `TIOCSWINSZ`. This ensures clients never reads a + `0x0` terminal size (https://codeberg.org/dnkl/foot/issues/20). ### Security diff --git a/terminal.c b/terminal.c index 4f9d1d5d..8181a610 100644 --- a/terminal.c +++ b/terminal.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -759,6 +760,13 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper, goto close_fds; } + if (ioctl(ptmx, TIOCSWINSZ, + &(struct winsize){.ws_row = 24, .ws_col = 80}) < 0) + { + LOG_ERRNO("failed to set initial TIOCSWINSZ"); + goto close_fds; + } + int ptmx_flags; if ((ptmx_flags = fcntl(ptmx, F_GETFL)) < 0 || fcntl(ptmx, F_SETFL, ptmx_flags | O_NONBLOCK) < 0)