]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
fix nmhandle attach/detach errors in tcpdnsconnect_cb()
authorOndřej Surý <ondrej@sury.org>
Wed, 4 Nov 2020 19:59:31 +0000 (20:59 +0100)
committerOndřej Surý <ondrej@sury.org>
Sat, 7 Nov 2020 19:49:53 +0000 (20:49 +0100)
we need to attach to the statichandle when connecting TCPDNS sockets,
same as with UDP.

lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcpdns.c

index d5cd81364678576e5d3ed84474295b4788197a54..96073495323af5c912d26a341443e90dce55bb5f 100644 (file)
@@ -1206,7 +1206,8 @@ isc__nmhandle_get(isc_nmsocket_t *sock, isc_sockaddr_t *peer,
        UNLOCK(&sock->lock);
 
        if (sock->type == isc_nm_tcpsocket ||
-           (sock->type == isc_nm_udpsocket && atomic_load(&sock->client)))
+           (sock->type == isc_nm_udpsocket && atomic_load(&sock->client)) ||
+           (sock->type == isc_nm_tcpdnssocket && atomic_load(&sock->client)))
        {
                INSIST(sock->statichandle == NULL);
 
index d7d4dbb0d3fbb2f881a3b823477a3cf486428912..ad85928d17c30efb6cb4ab1f7ba9958ef5b010f4 100644 (file)
@@ -736,6 +736,7 @@ tcpdnsconnect_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
        void *cbarg = conn->cbarg;
        size_t extrahandlesize = conn->extrahandlesize;
        isc_nmsocket_t *dnssock = NULL;
+       isc_nmhandle_t *readhandle = NULL;
 
        REQUIRE(result != ISC_R_SUCCESS || VALID_NMHANDLE(handle));
 
@@ -758,7 +759,13 @@ tcpdnsconnect_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
        dnssock->tid = isc_nm_tid();
 
        atomic_init(&dnssock->client, true);
-       dnssock->statichandle = isc__nmhandle_get(dnssock, NULL, NULL);
+
+       readhandle = isc__nmhandle_get(dnssock, NULL, NULL);
+
+       INSIST(dnssock->statichandle != NULL);
+       INSIST(dnssock->statichandle == readhandle);
+       INSIST(readhandle->sock == dnssock);
+       INSIST(dnssock->recv_cb == NULL);
 
        uv_timer_init(&dnssock->mgr->workers[isc_nm_tid()].loop,
                      &dnssock->timer);
@@ -774,7 +781,11 @@ tcpdnsconnect_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) {
         * packet.
         */
        isc_nm_read(handle, dnslisten_readcb, dnssock);
-       cb(dnssock->statichandle, ISC_R_SUCCESS, cbarg);
+       cb(readhandle, ISC_R_SUCCESS, cbarg);
+
+       /*
+        * The sock is now attached to the handle.
+        */
        isc__nmsocket_detach(&dnssock);
 }