]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix resquery reference imbalance on TCP connect failure
authorOndřej Surý <ondrej@isc.org>
Fri, 6 Mar 2026 16:06:24 +0000 (17:06 +0100)
committerOndřej Surý <ondrej@sury.org>
Sun, 15 Mar 2026 02:13:00 +0000 (03:13 +0100)
In fctx_query(), resquery_ref(query) is called before
dns_dispatch_connect() in anticipation of the resquery_connected()
callback consuming the reference.

When dns_dispatch_connect() fails synchronously on TCP (e.g. from
dns_transport_get_tlsctx() failing in tcp_dispatch_connect()), the
connect callback is never scheduled, so the extra reference is never
consumed.  The error path then tears down the query via manual cleanup
(isc_mem_put) without going through the refcount destructor, leaving
the reference imbalanced.

Fix by dropping the extra reference on the error path, just after
dns_dispatch_done() which cleans up the dispatch entry.

(cherry picked from commit 2da669490ca94b9617257a25d93a52ed67dfdd14)

lib/dns/resolver.c

index 1a3bfb054f1ba679b6120ca2d77c0d5a12d0c788..24e2d8f1f0d23e96827fb307ccf57be462c1b4bd 100644 (file)
@@ -2187,10 +2187,11 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
                        isc_log_write(
                                dns_lctx, DNS_LOGCATEGORY_RESOLVER,
                                DNS_LOGMODULE_RESOLVER, log_level,
-                               "Unable to establish a connection to %s: %s\n",
+                               "Unable to establish a connection to %s: %s",
                                peerbuf, isc_result_totext(result));
                }
                dns_dispatch_done(&query->dispentry);
+               resquery_unref(query);
                goto cleanup_fetch;
        } else {
                RUNTIME_CHECK(result == ISC_R_SUCCESS);