]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
attach socket before async streamdns_resume_processing
authorColin Vidal <colin@isc.org>
Tue, 18 Nov 2025 09:31:24 +0000 (10:31 +0100)
committerColin Vidal <colin@isc.org>
Thu, 20 Nov 2025 17:08:52 +0000 (18:08 +0100)
Call to `streamdns_resume_processing` is asynchronous but the socket
passed as argument is not attached when scheduling the call.

While there is no reproducible way (so far) to make the socket reference
number down to 0 before `streamdns_resume_processing` is called, attach
the socket before scheduling the call. This guard against an hypothetic
case where, for some reasons, the socket refcount would reach 0, and be
freed from memory when `streamdns_resume_processing` is called.

lib/isc/netmgr/streamdns.c

index 2da8a63a0aa40bb24e73445e26fc9dae76b20262..9dd8b0aeab61808cd80df34ea5084458fa2c116f 100644 (file)
@@ -93,6 +93,8 @@ streamdns_closing(isc_nmsocket_t *sock);
 
 static void
 streamdns_resume_processing(void *arg);
+static void
+async_streamdns_resume_processing(void *arg);
 
 static void
 streamdns_resumeread(isc_nmsocket_t *sock, isc_nmhandle_t *transphandle) {
@@ -193,8 +195,9 @@ streamdns_on_complete_dnsmessage(isc_dnsstream_assembler_t *dnsasm,
                 * Process more DNS messages in the next loop tick.
                 */
                streamdns_pauseread(sock, transphandle);
-               isc_async_run(sock->worker->loop, streamdns_resume_processing,
-                             sock);
+               isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL });
+               isc_async_run(sock->worker->loop,
+                             async_streamdns_resume_processing, sock);
        }
 
        return false;
@@ -690,6 +693,15 @@ streamdns_resume_processing(void *arg) {
        streamdns_handle_incoming_data(sock, sock->outerhandle, NULL, 0);
 }
 
+static void
+async_streamdns_resume_processing(void *arg) {
+       isc_nmsocket_t *sock = (isc_nmsocket_t *)arg;
+
+       streamdns_resume_processing(sock);
+
+       isc__nmsocket_detach(&sock);
+}
+
 static isc_result_t
 streamdns_accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
        isc_nmsocket_t *listensock = (isc_nmsocket_t *)cbarg;