From: Marek Vavrusa Date: Wed, 11 May 2016 00:45:12 +0000 (-0700) Subject: daemon: do not modify task for outgoing queries X-Git-Tag: v1.0.0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5b0232bcefe8c64ce2234c495bd398a9dc80248;p=thirdparty%2Fknot-resolver.git daemon: do not modify task for outgoing queries if the upstream TCP query timeouted or the connection was severed, it would dissociate the handle from original query, so the query would be solved but the requestor wouldn't see the answer unless he requeried --- diff --git a/daemon/worker.c b/daemon/worker.c index ae36051d9..c3fb3feb5 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -820,13 +820,17 @@ int worker_process_tcp(struct worker_ctx *worker, uv_handle_t *handle, const uin struct session *session = handle->data; if (len <= 0 || !msg) { /* If we have pending tasks, we must dissociate them from the - * connection so they don't try to access closed and freed handle */ - for (size_t i = 0; i < session->tasks.len; ++i) { - struct qr_task *task = session->tasks.at[i]; - task->session = NULL; - task->source.handle = NULL; + * connection so they don't try to access closed and freed handle. + * @warning Do not modify task if this is outgoing request as it is shared with originator. + */ + if (!session->outgoing) { + for (size_t i = 0; i < session->tasks.len; ++i) { + struct qr_task *task = session->tasks.at[i]; + task->session = NULL; + task->source.handle = NULL; + } + session->tasks.len = 0; } - session->tasks.len = 0; return kr_error(ECONNRESET); } @@ -877,7 +881,7 @@ int worker_process_tcp(struct worker_ctx *worker, uv_handle_t *handle, const uin } /* Message is too long, can't process it. */ ssize_t to_read = MIN(len, task->bytes_remaining); - if (to_read > (ssize_t)(pkt_buf->max_size - pkt_buf->size)) { + if (pkt_buf->size + to_read > pkt_buf->max_size) { pkt_buf->size = 0; task->bytes_remaining = 0; return kr_error(EMSGSIZE);