]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Address potential double unlock in process_fd
authorMark Andrews <marka@isc.org>
Tue, 7 Jul 2020 01:11:15 +0000 (11:11 +1000)
committerMark Andrews <marka@isc.org>
Mon, 13 Jul 2020 21:35:17 +0000 (07:35 +1000)
(cherry picked from commit cc0089c66b692d554e8fc927e4f47e3d7dcda371)

lib/isc/unix/socket.c

index 0bb7bdfb3cf9129d9bfbd4d2e219d3385237e78d..c5f2979c5523528491d7781a6118d296706ddfb9 100644 (file)
@@ -3074,7 +3074,6 @@ finish:
                unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
                           SELECT_POKE_READ);
        }
-       UNLOCK(&sock->lock);
 }
 
 static void
@@ -3114,7 +3113,6 @@ finish:
                unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
                           SELECT_POKE_WRITE);
        }
-       UNLOCK(&sock->lock);
 }
 
 /*
@@ -3160,14 +3158,6 @@ process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) {
        }
 
        REQUIRE(readable || writeable);
-       if (readable) {
-               if (sock->listener) {
-                       internal_accept(sock);
-               } else {
-                       internal_recv(sock);
-               }
-       }
-
        if (writeable) {
                if (sock->connecting) {
                        internal_connect(sock);
@@ -3176,7 +3166,17 @@ process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) {
                }
        }
 
-       /* sock->lock is unlocked in internal_* function */
+       if (readable) {
+               if (sock->listener) {
+                       internal_accept(sock); /* unlocks sock */
+               } else {
+                       internal_recv(sock);
+                       UNLOCK(&sock->lock);
+               }
+       } else {
+               UNLOCK(&sock->lock);
+       }
+
        UNLOCK(&thread->fdlock[lockid]);
 
        /*
@@ -4952,7 +4952,6 @@ internal_connect(isc__socket_t *sock) {
 finish:
        unwatch_fd(&sock->manager->threads[sock->threadid], sock->fd,
                   SELECT_POKE_CONNECT);
-       UNLOCK(&sock->lock);
 }
 
 isc_result_t