From 5a79bf01f28f1d61023153f40bd1c0a5ed9b4558 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Thu, 31 Aug 2017 01:16:11 +0200 Subject: [PATCH] Added patch to fix handling of empty string in WS_getaddrinfo. --- patches/patchinstall.sh | 16 +++ ...ing-of-empty-string-in-WS_getaddrinf.patch | 110 ++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 patches/ws2_32-getaddrinfo/0001-ws2_32-Fix-handling-of-empty-string-in-WS_getaddrinf.patch diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 2373d518..a374c30a 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -504,6 +504,7 @@ patch_enable_all () enable_ws2_32_TransmitFile="$1" enable_ws2_32_WSACleanup="$1" enable_ws2_32_WriteWatches="$1" + enable_ws2_32_getaddrinfo="$1" enable_ws2_32_getsockopt="$1" enable_ws2_32_setsockopt="$1" enable_wtsapi32_EnumerateProcesses="$1" @@ -1785,6 +1786,9 @@ patch_enable () ws2_32-WriteWatches) enable_ws2_32_WriteWatches="$2" ;; + ws2_32-getaddrinfo) + enable_ws2_32_getaddrinfo="$2" + ;; ws2_32-getsockopt) enable_ws2_32_getsockopt="$2" ;; @@ -10439,6 +10443,18 @@ if test "$enable_ws2_32_WSACleanup" -eq 1; then ) >> "$patchlist" fi +# Patchset ws2_32-getaddrinfo +# | +# | Modified files: +# | * dlls/ws2_32/socket.c +# | +if test "$enable_ws2_32_getaddrinfo" -eq 1; then + patch_apply ws2_32-getaddrinfo/0001-ws2_32-Fix-handling-of-empty-string-in-WS_getaddrinf.patch + ( + printf '%s\n' '+ { "Sebastian Lackner", "ws2_32: Fix handling of empty string in WS_getaddrinfo.", 1 },'; + ) >> "$patchlist" +fi + # Patchset ws2_32-getsockopt # | # | This patchset fixes the following Wine bugs: diff --git a/patches/ws2_32-getaddrinfo/0001-ws2_32-Fix-handling-of-empty-string-in-WS_getaddrinf.patch b/patches/ws2_32-getaddrinfo/0001-ws2_32-Fix-handling-of-empty-string-in-WS_getaddrinf.patch new file mode 100644 index 00000000..6122f894 --- /dev/null +++ b/patches/ws2_32-getaddrinfo/0001-ws2_32-Fix-handling-of-empty-string-in-WS_getaddrinf.patch @@ -0,0 +1,110 @@ +From b69f0c678ad23c7ee96ec82d18bf3162afe1dac6 Mon Sep 17 00:00:00 2001 +From: Sebastian Lackner +Date: Thu, 31 Aug 2017 01:15:05 +0200 +Subject: ws2_32: Fix handling of empty string in WS_getaddrinfo. + +Fixes a regression introduced in a2053597cc326e2305c44e1c1a954c2e0ee2853e. +--- + dlls/ws2_32/socket.c | 38 ++++++++++++++++++++++++++++++-------- + 1 file changed, 30 insertions(+), 8 deletions(-) + +diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c +index dce52e8fd08..45764f5a359 100644 +--- a/dlls/ws2_32/socket.c ++++ b/dlls/ws2_32/socket.c +@@ -6634,6 +6634,22 @@ static int convert_eai_u2w(int unixret) { + return unixret; + } + ++static char *get_hostname(void) ++{ ++ char *ret; ++ DWORD size = 0; ++ ++ GetComputerNameExA( ComputerNamePhysicalDnsHostname, NULL, &size ); ++ if (GetLastError() != ERROR_MORE_DATA) return NULL; ++ if (!(ret = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL; ++ if (!GetComputerNameExA( ComputerNamePhysicalDnsHostname, ret, &size )) ++ { ++ HeapFree( GetProcessHeap(), 0, ret ); ++ return NULL; ++ } ++ return ret; ++} ++ + static char *get_fqdn(void) + { + char *ret; +@@ -6659,9 +6675,8 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr + struct addrinfo *unixaires = NULL; + int result; + struct addrinfo unixhints, *punixhints = NULL; +- char *dot, *nodeV6 = NULL, *fqdn; ++ char *nodeV6 = NULL, *hostname, *fqdn; + const char *node; +- size_t hostname_len = 0; + + *res = NULL; + if (!nodename && !servname) +@@ -6670,16 +6685,20 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr + return WSAHOST_NOT_FOUND; + } + ++ hostname = get_hostname(); ++ if (!hostname) return WSA_NOT_ENOUGH_MEMORY; ++ + fqdn = get_fqdn(); +- if (!fqdn) return WSA_NOT_ENOUGH_MEMORY; +- dot = strchr(fqdn, '.'); +- if (dot) +- hostname_len = dot - fqdn; ++ if (!fqdn) ++ { ++ HeapFree(GetProcessHeap(), 0, hostname); ++ return WSA_NOT_ENOUGH_MEMORY; ++ } + + if (!nodename) + node = NULL; + else if (!nodename[0]) +- node = fqdn; ++ node = hostname; + else + { + node = nodename; +@@ -6694,6 +6713,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr + nodeV6 = HeapAlloc(GetProcessHeap(), 0, close_bracket - node); + if (!nodeV6) + { ++ HeapFree(GetProcessHeap(), 0, hostname); + HeapFree(GetProcessHeap(), 0, fqdn); + return WSA_NOT_ENOUGH_MEMORY; + } +@@ -6723,6 +6743,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr + if (punixhints->ai_socktype < 0) + { + SetLastError(WSAESOCKTNOSUPPORT); ++ HeapFree(GetProcessHeap(), 0, hostname); + HeapFree(GetProcessHeap(), 0, fqdn); + HeapFree(GetProcessHeap(), 0, nodeV6); + return SOCKET_ERROR; +@@ -6748,7 +6769,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr + result = getaddrinfo(node, servname, punixhints, &unixaires); + + if (result && (!hints || !(hints->ai_flags & WS_AI_NUMERICHOST)) +- && (!strcmp(fqdn, node) || (!strncmp(fqdn, node, hostname_len) && !node[hostname_len]))) ++ && (!strcmp(node, hostname) || !strcmp(node, fqdn))) + { + /* If it didn't work it means the host name IP is not in /etc/hosts, try again + * by sending a NULL host and avoid sending a NULL servname too because that +@@ -6757,6 +6778,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr + result = getaddrinfo(NULL, servname ? servname : "0", punixhints, &unixaires); + } + TRACE("%s, %s %p -> %p %d\n", debugstr_a(nodename), debugstr_a(servname), hints, res, result); ++ HeapFree(GetProcessHeap(), 0, hostname); + HeapFree(GetProcessHeap(), 0, fqdn); + HeapFree(GetProcessHeap(), 0, nodeV6); + +-- +2.14.1 +