summaryrefslogtreecommitdiff
path: root/src/include/port/win32/sys/socket.h
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2024-02-12 10:47:57 +1300
committerThomas Munro <tmunro@postgresql.org>2024-02-12 11:14:42 +1300
commit0460e4ecc0fa532468331a4b71ad0fbe8ff1a416 (patch)
treed0ce9d3107b3f464328df24bd2912a5fec064262 /src/include/port/win32/sys/socket.h
parent4eb261165d1294f590c7c279a8825e73abe57ecd (diff)
Fix gai_strerror() thread-safety on Windows.
Commit 5579388d removed code that supplied a fallback implementation of getaddrinfo(), which was dead code on modern systems. One tiny piece of the removed code was still doing something useful on Windows, though: that OS's own gai_strerror()/gai_strerrorA() function returns a pointer to a static buffer that it overwrites each time, so it's not thread-safe. In rare circumstances, a multi-threaded client program could get an incorrect or corrupted error message. Restore the replacement gai_strerror() function, though now that it's only for Windows we can put it into a win32-specific file and cut it down to the errors that Windows documents. The error messages here are taken from FreeBSD, because Windows' own messages seemed too verbose. Back-patch to 16. Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGKz%2BF9d2PTiXwfYV7qJw%2BWg2jzACgSDgPizUw7UG%3Di58A%40mail.gmail.com
Diffstat (limited to 'src/include/port/win32/sys/socket.h')
-rw-r--r--src/include/port/win32/sys/socket.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/include/port/win32/sys/socket.h b/src/include/port/win32/sys/socket.h
index 0c32c0f7b2e..f2b475df5e5 100644
--- a/src/include/port/win32/sys/socket.h
+++ b/src/include/port/win32/sys/socket.h
@@ -23,4 +23,12 @@
#define ERROR PGERROR
#endif
+/*
+ * We don't use the Windows gai_strerror[A] function because it is not
+ * thread-safe. We define our own in src/port/win32gai_strerror.c.
+ */
+#undef gai_strerror
+
+extern const char *gai_strerror(int ecode);
+
#endif /* WIN32_SYS_SOCKET_H */