From 95e3a6e67e093741dc6cef37dad3618b5924fa45 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 21 Sep 2020 19:31:15 +0200 Subject: terminal: fix segfault when backgrounding In the recent terminal commit, I "compressed" the read() error handling, and messed it up. The return value could be -1 for other non-fatal errors (such as EIO when trying to read while backgrounded), which resulted in buf.len getting messed up. Fixes: 602384348e718c77 --- osdep/terminal-unix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'osdep') diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index 80f7b20ddf..8e4d75f78b 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -404,8 +404,10 @@ static void *terminal_thread(void *ptr) int retval = read(tty_in, &buf.b[buf.len], BUF_LEN - buf.len); if (!retval || (retval == -1 && (errno == EBADF || errno == EINVAL))) break; // EOF/closed - buf.len += retval; - process_input(input_ctx, false); + if (retval > 0) { + buf.len += retval; + process_input(input_ctx, false); + } } if (r == 0) process_input(input_ctx, true); -- cgit v1.2.3