From 81879db2dbb16959bbc74fdfc624aa92863bc0ca Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Sep 2017 12:24:31 +0530 Subject: [PATCH] Fix new_input_at not protected by read lock --- kitty/child-monitor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index d6ab5d22d..0ffb168f1 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -691,6 +691,7 @@ read_bytes(int fd, Screen *screen) { if (orig_sz >= READ_BUF_SZ) { screen_mutex(unlock, read); return true; } // screen read buffer is full available_buffer_space = READ_BUF_SZ - orig_sz; screen_mutex(unlock, read); + while(true) { len = read(fd, screen->read_buf + orig_sz, available_buffer_space); if (len < 0) { @@ -701,8 +702,9 @@ read_bytes(int fd, Screen *screen) { break; } if (UNLIKELY(len == 0)) return false; - if (screen->new_input_at == 0) screen->new_input_at = monotonic(); + screen_mutex(lock, read); + if (screen->new_input_at == 0) screen->new_input_at = monotonic(); if (orig_sz != screen->read_buf_sz) { // The other thread consumed some of the screen read buffer memmove(screen->read_buf + screen->read_buf_sz, screen->read_buf + orig_sz, len);