]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Obtain a client->handle reference when calling async_restart
authorMark Andrews <marka@isc.org>
Fri, 8 Dec 2023 02:57:14 +0000 (13:57 +1100)
committerMark Andrews <marka@isc.org>
Tue, 19 Dec 2023 15:50:48 +0000 (02:50 +1100)
otherwise client may be freed before async_restart is called.

lib/ns/include/ns/client.h
lib/ns/query.c

index db938bc4f5656803aebc9756968d9e8c8acdd3a5..345f5e778248fe0f523a17fa8fc7542d40e7233c 100644 (file)
@@ -169,11 +169,12 @@ struct ns_client {
        unsigned int     attributes;
        dns_view_t      *view;
        dns_dispatch_t  *dispatch;
-       isc_nmhandle_t  *handle;      /* Permanent pointer to handle */
-       isc_nmhandle_t  *sendhandle;  /* Waiting for send callback */
-       isc_nmhandle_t  *reqhandle;   /* Waiting for request callback
-                                        (query, update, notify) */
-       isc_nmhandle_t *updatehandle; /* Waiting for update callback */
+       isc_nmhandle_t  *handle;       /* Permanent pointer to handle */
+       isc_nmhandle_t  *sendhandle;   /* Waiting for send callback */
+       isc_nmhandle_t  *reqhandle;    /* Waiting for request callback
+                                         (query, update, notify) */
+       isc_nmhandle_t *updatehandle;  /* Waiting for update callback */
+       isc_nmhandle_t *restarthandle; /* Waiting for restart callback */
        unsigned char  *tcpbuf;
        size_t          tcpbuf_size;
        dns_message_t  *message;
index ff8856127f9a12cee68c20a91dc53be9bc2995b7..34e47e2b1e0fc151e484b44528298f322fdc7ab2 100644 (file)
@@ -5834,6 +5834,9 @@ static void
 async_restart(void *arg) {
        query_ctx_t *qctx = arg;
        ns_client_t *client = qctx->client;
+       isc_nmhandle_t *handle = client->restarthandle;
+
+       client->restarthandle = NULL;
 
        ns__query_start(qctx);
 
@@ -5841,6 +5844,7 @@ async_restart(void *arg) {
        qctx_freedata(qctx);
        qctx_destroy(qctx);
        isc_mem_put(client->manager->mctx, qctx, sizeof(*qctx));
+       isc_nmhandle_detach(&handle);
 }
 
 /*
@@ -11642,6 +11646,8 @@ ns_query_done(query_ctx_t *qctx) {
                saved_qctx = isc_mem_get(qctx->client->manager->mctx,
                                         sizeof(*saved_qctx));
                qctx_save(qctx, saved_qctx);
+               isc_nmhandle_attach(qctx->client->handle,
+                                   &qctx->client->restarthandle);
                isc_async_run(qctx->client->manager->loop, async_restart,
                              saved_qctx);
                return (DNS_R_CONTINUE);