diff options
author | Nadav Tasher <tashernadav@gmail.com> | 2024-12-20 16:59:01 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2025-01-22 09:20:14 +0100 |
commit | 113c12ee8cee2be232a361da277a2ab48807eeed (patch) | |
tree | 95c9c91119b70ffa95b15d3e24baa7e8d1ed769e /apps/lib | |
parent | Support boolean queries against provider config (diff) | |
download | openssl-113c12ee8cee2be232a361da277a2ab48807eeed.tar.xz openssl-113c12ee8cee2be232a361da277a2ab48807eeed.zip |
s_socket: naccept: close listening socket after accepting clients
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)
Diffstat (limited to 'apps/lib')
-rw-r--r-- | apps/lib/s_socket.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c index 658192421d..4372b9b73f 100644 --- a/apps/lib/s_socket.c +++ b/apps/lib/s_socket.c @@ -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; |