]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
s_socket: naccept: close listening socket after accepting clients
authorNadav Tasher <tashernadav@gmail.com>
Fri, 20 Dec 2024 15:59:01 +0000 (17:59 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 22 Jan 2025 08:20:14 +0000 (09:20 +0100)
When `-naccept` is passed (i.e with `s_server`), the listening socket remains open while handling
client, even after `naccept` is supposed to reach `0`.

This is caused to to the decrementation of `naccept` and closing of the socket
happening a little too late in the `do_server` function.

Signed-off-by: Nadav Tasher <tashernadav@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26228)

apps/lib/s_socket.c

index 658192421d9b4d69eb0588f19fe69a36f33b43bc..4372b9b73f8f6c47477be9a9ea7d74626ab00a6b 100644 (file)
@@ -411,6 +411,12 @@ int do_server(int *accept_sock, const char *host, const char *port,
                 BIO_closesocket(asock);
                 break;
             }
+
+            if (naccept != -1)
+                naccept--;
+            if (naccept == 0)
+                BIO_closesocket(asock);
+
             BIO_set_tcp_ndelay(sock, 1);
             i = (*cb)(sock, type, protocol, context);
 
@@ -441,11 +447,12 @@ int do_server(int *accept_sock, const char *host, const char *port,
 
             BIO_closesocket(sock);
         } else {
+            if (naccept != -1)
+                naccept--;
+
             i = (*cb)(asock, type, protocol, context);
         }
 
-        if (naccept != -1)
-            naccept--;
         if (i < 0 || naccept == 0) {
             BIO_closesocket(asock);
             ret = i;