]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Avoid running get_matching_view() asynchronously on an error path
authorAram Sargsyan <aram@isc.org>
Mon, 3 Jun 2024 10:49:46 +0000 (10:49 +0000)
committerNicki Křížek <nicki@isc.org>
Mon, 10 Jun 2024 15:35:40 +0000 (17:35 +0200)
Also create a new ns_client_async_reset() static function to decrease
code duplication.

bin/named/server.c
lib/ns/client.c

index dc16659341f10355e031a6eeedf07efdcfece6fe..fd12287d336ad8731357eb3c5a7ae110cf66dad6 100644 (file)
@@ -10234,6 +10234,15 @@ get_matching_view(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
                return (*viewmatchresult);
        }
 
+       /* Also no offloading when there is no view at all to match against. */
+       view = get_matching_view_next(NULL, message->rdclass);
+       if (view == NULL) {
+               *viewmatchresult = ISC_R_NOTFOUND;
+               return (*viewmatchresult);
+       }
+
+       dns_message_resetsig(message);
+
        matching_view_ctx_t *mvctx = isc_mem_get(message->mctx, sizeof(*mvctx));
        *mvctx = (matching_view_ctx_t){
                .srcaddr = srcaddr,
@@ -10250,15 +10259,6 @@ get_matching_view(isc_netaddr_t *srcaddr, isc_netaddr_t *destaddr,
        isc_loop_attach(loop, &mvctx->loop);
        dns_message_attach(message, &mvctx->message);
 
-       dns_message_resetsig(message);
-
-       view = get_matching_view_next(NULL, message->rdclass);
-       if (view == NULL) {
-               *mvctx->viewmatchresult = ISC_R_NOTFOUND;
-               isc_async_run(loop, get_matching_view_done, mvctx);
-               return (DNS_R_WAIT);
-       }
-
        /*
         * If the message has a SIG0 signature which we are going to
         * check, and the client is not exempt from the SIG(0) quota,
index 8d91ad07d04a711011114aa19a7ca1a6b70bcb91..7351c91923fa6c92bf696533605afebd75f12629 100644 (file)
@@ -1683,6 +1683,16 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) {
        return (result);
 }
 
+static void
+ns_client_async_reset(ns_client_t *client) {
+       if (client->async) {
+               client->async = false;
+               if (client->handle != NULL) {
+                       isc_nmhandle_unref(client->handle);
+               }
+       }
+}
+
 void
 ns__client_reset_cb(void *client0) {
        ns_client_t *client = client0;
@@ -1709,12 +1719,7 @@ ns__client_reset_cb(void *client0) {
                client->keytag_len = 0;
        }
 
-       if (client->async) {
-               client->async = false;
-               if (client->handle != NULL) {
-                       isc_nmhandle_unref(client->handle);
-               }
-       }
+       ns_client_async_reset(client);
 
        client->state = NS_CLIENTSTATE_READY;
 
@@ -1749,12 +1754,7 @@ ns__client_put_cb(void *client0) {
                dns_message_puttemprdataset(client->message, &client->opt);
        }
 
-       if (client->async) {
-               client->async = false;
-               if (client->handle != NULL) {
-                       isc_nmhandle_unref(client->handle);
-               }
-       }
+       ns_client_async_reset(client);
 
        dns_message_detach(&client->message);
 
@@ -1786,19 +1786,22 @@ ns_client_setup_view(ns_client_t *client, isc_netaddr_t *netaddr) {
                ns_client_request_continue, client, &client->sigresult,
                &client->viewmatchresult, &client->view);
 
+       /* Async mode. */
        if (result == DNS_R_WAIT) {
                INSIST(client->async == true);
                return (DNS_R_WAIT);
        }
 
        /*
-        * matchingview() is allowed to return anything other than DNS_R_WAIT
-        * only in non-async mode, in which case 'result' must be equal to
+        * matchingview() returning anything other than DNS_R_WAIT means it's
+        * not running in async mode, in which case 'result' must be equal to
         * 'client->viewmatchresult'.
         */
-       INSIST(client->async == false);
        INSIST(result == client->viewmatchresult);
 
+       /* Non-async mode. */
+       ns_client_async_reset(client);
+
        return (result);
 }
 
@@ -2480,17 +2483,7 @@ ns_client_request_continue(void *arg) {
        }
 
 cleanup:
-
-       /*
-        * If we are running async then 'unref' the handle and reset the async
-        * flag, so that the destructor doesn't try to 'unref' the handle too.
-        */
-       if (client->async) {
-               client->async = false;
-               if (client->handle != NULL) {
-                       isc_nmhandle_unref(client->handle);
-               }
-       }
+       ns_client_async_reset(client);
 }
 
 isc_result_t