From c41ce8e0c94ba9cc6bf18d4bbbcc977af93afbf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Witold=20Kr=C4=99cicki?= Date: Tue, 27 Oct 2020 10:09:30 +0100 Subject: [PATCH] Properly handle outer TCP connection closed in TCPDNS. If the connection is closed while we're processing the request we might access TCPDNS outerhandle which is already reset. Check for this condition and call the callback with ISC_R_CANCELED result. --- lib/isc/netmgr/tcpdns.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/isc/netmgr/tcpdns.c b/lib/isc/netmgr/tcpdns.c index 6a20ea4c7c3..63391273cb1 100644 --- a/lib/isc/netmgr/tcpdns.c +++ b/lib/isc/netmgr/tcpdns.c @@ -596,9 +596,16 @@ isc__nm_tcpdns_send(isc_nmhandle_t *handle, isc_region_t *region, r.base = (unsigned char *)uvreq->uvbuf.base; r.length = uvreq->uvbuf.len; - - isc_nmhandle_attach(sock->outerhandle, &sendhandle); - isc_nm_send(sock->outerhandle, &r, tcpdnssend_cb, uvreq); + if (sock->outerhandle != NULL) { + isc_nmhandle_attach(sock->outerhandle, &sendhandle); + isc_nm_send(sock->outerhandle, &r, tcpdnssend_cb, + uvreq); + } else { + cb(handle, ISC_R_CANCELED, cbarg); + isc_mem_put(sock->mgr->mctx, uvreq->uvbuf.base, + uvreq->uvbuf.len); + isc__nm_uvreq_put(&uvreq, sock); + } } else { isc__netievent_tcpdnssend_t *ievent = NULL; -- 2.47.3