diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-02-05 18:50:49 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-02-05 18:50:49 +0000 |
| commit | 9d52c422e1856ee1de759254f6ca9046bae5e485 (patch) | |
| tree | f31a2fde532fba8f172229eb7cef7d67f8605417 | |
| parent | log: log to stderr, not stdout (diff) | |
term: always read *all* we can from the client before updating state
But place an upper limit on the number of iterations we read, to
prevent starvation caused by a bad behaving client to constantly
writes data.
| -rw-r--r-- | terminal.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -147,18 +147,25 @@ fdm_ptmx(struct fdm *fdm, int fd, int events, void *data) return true; #endif + /* Prevent blinking while typing */ + term_cursor_blink_restart(term); + uint8_t buf[24 * 1024]; - ssize_t count = pollin ? read(term->ptmx, buf, sizeof(buf)) : 0; + ssize_t count = sizeof(buf); - if (count < 0) { - LOG_ERRNO("failed to read from pseudo terminal"); - return false; - } + const size_t max_iterations = 1024; - vt_from_slave(term, buf, count); + for (size_t i = 0; i < max_iterations && pollin && count == sizeof(buf); i++) { + assert(pollin); + count = read(term->ptmx, buf, sizeof(buf)); - /* Prevent blinking while typing */ - term_cursor_blink_restart(term); + if (count < 0) { + LOG_ERRNO("failed to read from pseudo terminal"); + return false; + } + + vt_from_slave(term, buf, count); + } /* * We likely need to re-render. But, we don't want to |
