From 875cd5af7b0af2859efd26b83776f5dcea963960 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Fri, 27 Dec 2019 13:57:24 +0000 Subject: [PATCH] Stop reading from a client as soon as an error occurs on the socket --- src/server.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/server.c b/src/server.c index 6981756..f6188d9 100644 --- a/src/server.c +++ b/src/server.c @@ -718,19 +718,21 @@ static void on_client_read(uv_stream_t* stream, ssize_t n_read, struct nvnc_client* client = container_of( (uv_tcp_t*)stream, struct nvnc_client, stream_handle); - if (n_read == UV_EOF) { + if (n_read == 0) + return; + + if (n_read < 0) { + uv_read_stop(stream); client_unref(client); return; } - if (n_read < 0) - return; - assert(client->buffer_index == 0); - if (n_read > MSG_BUFFER_SIZE - client->buffer_len) { + if ((size_t)n_read > MSG_BUFFER_SIZE - client->buffer_len) { /* Can't handle this. Let's just give up */ client->state = VNC_CLIENT_STATE_ERROR; + uv_read_stop(stream); client_unref(client); return; }