From: Nadav Tasher Date: Fri, 20 Dec 2024 15:59:01 +0000 (+0200) Subject: s_socket: naccept: close listening socket after accepting clients X-Git-Tag: openssl-3.1.8~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9765cd86ecf4f962430c00eeba0120cb67ce063b;p=thirdparty%2Fopenssl.git 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 Reviewed-by: Neil Horman Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26228) (cherry picked from commit 113c12ee8cee2be232a361da277a2ab48807eeed) --- diff --git a/apps/lib/s_socket.c b/apps/lib/s_socket.c index 452714ea07a..4b3a055cc15 100644 --- a/apps/lib/s_socket.c +++ b/apps/lib/s_socket.c @@ -380,6 +380,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); @@ -410,11 +416,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;