]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Win32: gai_strerror → WSAGetLastError
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 1 Jan 2022 19:28:03 +0000 (20:28 +0100)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 26 Feb 2022 15:41:51 +0000 (16:41 +0100)
The Windows Sockets documentation recommends using WSAGetLastError()
instead of gai_strerror(), because the latter is not thread safe:
https://docs.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2

Properly decode the output using openconnect__win32_strerror().

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
ssl.c

diff --git a/ssl.c b/ssl.c
index 9e223504274d0e63a1e1d4a9c1422eb92c87617e..e77abba25c7dc27537a1ba4fe01ebb82a17d24b6 100644 (file)
--- a/ssl.c
+++ b/ssl.c
@@ -343,9 +343,17 @@ int connect_https_socket(struct openconnect_info *vpninfo)
                        err = getaddrinfo(hostname, port, &hints, &result);
 
                if (err) {
+#ifdef _WIN32
+                       char *errstr = openconnect__win32_strerror(WSAGetLastError());
+#else
+                       const char *errstr = gai_strerror(err);
+#endif
                        vpn_progress(vpninfo, PRG_ERR,
                                     _("getaddrinfo failed for host '%s': %s\n"),
-                                    hostname, gai_strerror(err));
+                                    hostname, errstr);
+#ifdef _WIN32
+                       free(errstr);
+#endif
                        if (hints.ai_flags & AI_NUMERICHOST)
                                free(hostname);
                        ssl_sock = -EINVAL;