From 5b1b29593e7ced9ca539c5aa04f70dc019531a5e Mon Sep 17 00:00:00 2001 From: Lai Jiangshan Date: Fri, 23 Sep 2016 12:04:40 +0800 Subject: [PATCH] check close before discarding the data Signed-off-by: Lai Jiangshan --- src/init.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/init.c b/src/init.c index 0e34b88..66d1bbc 100644 --- a/src/init.c +++ b/src/init.c @@ -1010,17 +1010,7 @@ static int hyper_ttyfd_handle(struct hyper_event *de, uint32_t len) return 0; } - wbuf = &exec->stdinev.wbuf; - - size = wbuf->size - wbuf->get; - if (size == 0) - return 0; - - /* Data may lost since pts buffer is full. do not allow one exec pts occupy all - * of the tty buff. */ - if (size > (len - 12)) - size = (len - 12); - + size = len - STREAM_HEADER_SIZE; /* size == 0 means we had received eof */ if (size == 0 && !exec->tty) { exec->close_stdin_request = 1; @@ -1031,6 +1021,12 @@ static int hyper_ttyfd_handle(struct hyper_event *de, uint32_t len) } } + wbuf = &exec->stdinev.wbuf; + if (size > (wbuf->size - wbuf->get)) { + /* buffer is full, discard the data */ + /* TODO: properly handle the discard data */ + size = wbuf->size - wbuf->get; + } if (size > 0) { memcpy(wbuf->data + wbuf->get, rbuf->data + 12, size); wbuf->get += size;