From: Vladimír Čunát Date: Wed, 28 Nov 2018 12:29:06 +0000 (+0100) Subject: daemon various nitpicks X-Git-Tag: v3.2.0~21^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98bf75231e59953fe6956fe5e2a3ac97facde15e;p=thirdparty%2Fknot-resolver.git daemon various nitpicks - session: data length would be difference between start and end indices, but the function is unused so why even have it? --- diff --git a/daemon/io.c b/daemon/io.c index ee65d4d93..855b35a94 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -184,9 +184,7 @@ void tcp_timeout_trigger(uv_timer_t *timer) static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) { - uv_loop_t *loop = handle->loop; struct session *s = handle->data; - assert(s && session_get_handle(s) == (uv_handle_t *)handle && handle->type == UV_TCP); @@ -200,8 +198,6 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) return; } - struct worker_ctx *worker = loop->data; - if (nread < 0 || !buf->base) { if (kr_verbose_status) { struct sockaddr *peer = session_get_peer(s); @@ -240,6 +236,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) worker_end_tcp(s); } session_wirebuf_compress(s); + struct worker_ctx *worker = handle->loop->data; mp_flush(worker->pkt_pool.ctx); } diff --git a/daemon/session.c b/daemon/session.c index 4e18b6a3e..c96a78397 100644 --- a/daemon/session.c +++ b/daemon/session.c @@ -689,11 +689,6 @@ uint8_t *session_wirebuf_get_start(struct session *session) return session->wire_buf; } -size_t session_wirebuf_get_len(struct session *session) -{ - return session->wire_buf_end_idx; -} - size_t session_wirebuf_get_size(struct session *session) { return session->wire_buf_size; diff --git a/daemon/session.h b/daemon/session.h index 654f93193..56f7eb4aa 100644 --- a/daemon/session.h +++ b/daemon/session.h @@ -119,8 +119,6 @@ int session_timer_stop(struct session *session); uint8_t *session_wirebuf_get_start(struct session *session); /** Get size of session wirebuffer. */ size_t session_wirebuf_get_size(struct session *session); -/** Get length of data in the session wirebuffer. */ -size_t session_wirebuf_get_len(struct session *session); /** Get pointer to the beginning of free space in session wirebuffer. */ uint8_t *session_wirebuf_get_free_start(struct session *session); /** Get amount of free space in session wirebuffer. */ diff --git a/daemon/tls.c b/daemon/tls.c index 3a3863981..6b63a9674 100644 --- a/daemon/tls.c +++ b/daemon/tls.c @@ -451,7 +451,12 @@ ssize_t tls_process_input_data(struct session *s, const uint8_t *buf, ssize_t nr } assert(tls_p->session == s); - assert(tls_p->recv_buf == buf && nread <= sizeof(tls_p->recv_buf)); + const bool ok = tls_p->recv_buf == buf && nread <= sizeof(tls_p->recv_buf); + if (!ok) { + assert(false); + /* don't risk overflowing the buffer if we have a mistake somewhere */ + return kr_error(EINVAL); + } const char *logstring = tls_p->client_side ? client_logstring : server_logstring;