From 0f879c8b613b5f4a6df852367756a4c32a2800fc Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Mon, 2 Jul 2018 12:31:57 +0200 Subject: [PATCH] Fix zero size reads In certain cases we may get zero size reads (e.g. if the server sends an rfc2217 notification without any other data). In this situation we must not propagate the zero size read to user space as it may be interpreted as end of input. I haven't found a way to tell fuse that it should just ignore this read but passing EINTR seems to work. --- ttynvt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/ttynvt.c b/ttynvt.c index 260cb53..025158f 100644 --- a/ttynvt.c +++ b/ttynvt.c @@ -407,10 +407,17 @@ ttynvt_read(fuse_req_t req, size_t size, off_t off, } if (size > tty->rxcnt) size = tty->rxcnt; - fuse_reply_buf(req, tty->buf, size); - memmove(tty->buf, tty->buf + size, tty->blen - size); - tty->blen -= size; - tty->rxcnt -= size; + if (size > 0) + { + fuse_reply_buf(req, tty->buf, size); + memmove(tty->buf, tty->buf + size, tty->blen - size); + tty->blen -= size; + tty->rxcnt -= size; + } + else + { + fuse_reply_err(req, EINTR); + } pthread_mutex_unlock(&tty->tty_lock); }