From: Levi Zim Date: Wed, 16 Apr 2025 06:21:33 +0000 (+0800) Subject: Avoid potential double close of client_skt in sslecho X-Git-Tag: openssl-3.4.2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22115761cd188b100e08e18065dbf90248523d1b;p=thirdparty%2Fopenssl.git Avoid potential double close of client_skt in sslecho The server_running variable is declared as volatile and some comments in the code are mentioning about implementing CTRL+C handler in the future. In the client handling loop, the client_skt is closed at the end of the loop if server_running is true. If (future) CTRL+C handler changes server_running to false at this time. The next accept will not happen and the exit clean up code will close client_skt for the second time. This patch fixes this potential double close by setting client_skt back to -1 after closing it. Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/27405) (cherry picked from commit 48e3fe08639d84bd557c0d5248f5600f2fb1f7de) --- diff --git a/demos/sslecho/main.c b/demos/sslecho/main.c index 6db50b1b08d..faa8b389551 100644 --- a/demos/sslecho/main.c +++ b/demos/sslecho/main.c @@ -264,6 +264,11 @@ int main(int argc, char **argv) SSL_shutdown(ssl); SSL_free(ssl); close(client_skt); + /* + * Set client_skt to -1 to avoid double close when + * server_running become false before next accept + */ + client_skt = -1; } } printf("Server exiting...\n");