From c0251d7b0fb835c6f043fa389b448d0d880d60a7 Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Tue, 4 Mar 2025 08:20:29 -0500 Subject: [PATCH] Fix build on windows xp Windows XP doesn't support setting socket handles to be non-inheritable, but the rio_notifier attempts to do so. WSASocketA will there return an error when the NO_INHERIT flag is set. In that case, just retry the call without the flag. Fixes #26943 Reviewed-by: Tim Hudson Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26970) --- ssl/rio/rio_notifier.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ssl/rio/rio_notifier.c b/ssl/rio/rio_notifier.c index fe62ad3c7e..f23ca443ae 100644 --- a/ssl/rio/rio_notifier.c +++ b/ssl/rio/rio_notifier.c @@ -71,9 +71,27 @@ static int create_socket(int domain, int socktype, int protocol) * Use WSASocketA to create a socket which is immediately marked as * non-inheritable, avoiding race conditions if another thread is about to * call CreateProcess. + * NOTE: windows xp (0x501) doesn't support the non-inheritance flag here + * but preventing inheritance isn't mandatory, just a safety precaution + * so we can get away with not including it for older platforms */ + +# ifdef WSA_FLAG_NO_HANDLE_INHERIT fd = (int)WSASocketA(domain, socktype, protocol, NULL, 0, WSA_FLAG_NO_HANDLE_INHERIT); + + /* + * Its also possible that someone is building a binary on a newer windows + * SDK, but running it on a runtime that doesn't support inheritance + * supression. In that case the above will return INVALID_SOCKET, and + * our response for those older platforms is to try the call again + * without the flag + */ + if (fd == INVALID_SOCKET) + fd = (int)WSASocketA(domain, socktype, protocol, NULL, 0, 0); +# else + fd = (int)WSASocketA(domain, socktype, protocol, NULL, 0, 0); +# endif if (fd == INVALID_SOCKET) { int err = get_last_socket_error();