]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix build on windows xp
authorNeil Horman <nhorman@openssl.org>
Tue, 4 Mar 2025 13:20:29 +0000 (08:20 -0500)
committerTomas Mraz <tomas@openssl.org>
Wed, 5 Mar 2025 16:36:20 +0000 (17:36 +0100)
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 <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26970)

ssl/rio/rio_notifier.c

index fe62ad3c7e83fc756095d2338bd112bdb40e3ffa..f23ca443ae0082eee1f805285577f050128a52ea 100644 (file)
@@ -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();