]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Synchronize dns_request_createraw() and dns_request_create() UDP timeout
authorAram Sargsyan <aram@isc.org>
Mon, 12 Dec 2022 11:55:09 +0000 (11:55 +0000)
committerAram Sargsyan <aram@isc.org>
Mon, 3 Apr 2023 16:18:39 +0000 (16:18 +0000)
The dns_request_createraw() function, unlike dns_request_create(), when
calculating the UDP timeout value, doesn't check that 'udpretries' is
not zero, and that is the more logical behavior, because the calculation
formula uses division to 'udpretries + 1', where '1' is the first try.

Change the dns_request_create() function to remove the 'udpretries != 0'
condition.

Add a 'REQUIRE(udpretries != UINT_MAX)' check to protect from a division
by zero.

Make the 'request->udpcount' field to represent the number of tries,
instead of the number of retries.

(cherry picked from commit 643abfbba7fe9eb7e2000ee3015c7e680cc590a2)

lib/dns/request.c

index e5066798f8775cb72ee103693aab10dff0c43228..1103bea49ff255c9e891c77c1734af29ccf74be9 100644 (file)
@@ -488,6 +488,8 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
        REQUIRE(action != NULL);
        REQUIRE(requestp != NULL && *requestp == NULL);
        REQUIRE(timeout > 0);
+       REQUIRE(udpretries != UINT_MAX);
+
        if (srcaddr != NULL) {
                REQUIRE(isc_sockaddr_pf(srcaddr) == isc_sockaddr_pf(destaddr));
        }
@@ -510,7 +512,7 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
                return (result);
        }
 
-       request->udpcount = udpretries;
+       request->udpcount = udpretries + 1;
 
        request->event = (dns_requestevent_t *)isc_event_allocate(
                mctx, task, DNS_EVENT_REQUESTDONE, action, arg,
@@ -531,7 +533,7 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
                request->timeout = timeout * 1000;
        } else {
                if (udptimeout == 0) {
-                       udptimeout = timeout / (udpretries + 1);
+                       udptimeout = timeout / request->udpcount;
                }
                if (udptimeout == 0) {
                        udptimeout = 1;
@@ -642,6 +644,7 @@ dns_request_create(dns_requestmgr_t *requestmgr, dns_message_t *message,
        REQUIRE(action != NULL);
        REQUIRE(requestp != NULL && *requestp == NULL);
        REQUIRE(timeout > 0);
+       REQUIRE(udpretries != UINT_MAX);
 
        mctx = requestmgr->mctx;
 
@@ -667,7 +670,7 @@ dns_request_create(dns_requestmgr_t *requestmgr, dns_message_t *message,
                return (result);
        }
 
-       request->udpcount = udpretries;
+       request->udpcount = udpretries + 1;
 
        request->event = (dns_requestevent_t *)isc_event_allocate(
                mctx, task, DNS_EVENT_REQUESTDONE, action, arg,
@@ -690,8 +693,8 @@ dns_request_create(dns_requestmgr_t *requestmgr, dns_message_t *message,
                tcp = true;
                request->timeout = timeout * 1000;
        } else {
-               if (udptimeout == 0 && udpretries != 0) {
-                       udptimeout = timeout / (udpretries + 1);
+               if (udptimeout == 0) {
+                       udptimeout = timeout / request->udpcount;
                }
                if (udptimeout == 0) {
                        udptimeout = 1;
@@ -1056,7 +1059,7 @@ req_response(isc_result_t result, isc_region_t *region, void *arg) {
 
        if (result == ISC_R_TIMEDOUT) {
                LOCK(&request->requestmgr->locks[request->hash]);
-               if (request->udpcount != 0) {
+               if (request->udpcount > 1) {
                        request->udpcount -= 1;
                        dns_dispatch_resume(request->dispentry,
                                            request->timeout);