Rebase against 2ee75bf9ade3e90f10ffe4236c8c95d817402392.

This commit is contained in:
Alistair Leslie-Hughes
2020-09-29 12:58:11 +10:00
parent 9acfa3b899
commit 639755741e
9 changed files with 116 additions and 109 deletions

View File

@@ -1,18 +1,18 @@
From 98db626566f8d4bcc0de8ad17fe0dabb685d69fe Mon Sep 17 00:00:00 2001
From 381a5842063016c8cec8810f81baaa7e07b790ac Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Thu, 31 Aug 2017 01:15:05 +0200
Subject: [PATCH] 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(-)
dlls/ws2_32/socket.c | 46 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 4d2afa946b7..ed1ca2f44b9 100644
index 05423d4b90c..71aaf433d1b 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -6673,6 +6673,22 @@ static int convert_eai_u2w(int unixret) {
@@ -6759,6 +6759,22 @@ static int convert_eai_u2w(int unixret) {
return unixret;
}
@@ -35,52 +35,56 @@ index 4d2afa946b7..ed1ca2f44b9 100644
static char *get_fqdn(void)
{
char *ret;
@@ -6698,9 +6714,8 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
@@ -6784,7 +6800,7 @@ 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;
- char *nodeV6 = NULL, *fqdn = NULL;
+ char *nodeV6 = NULL, *hostname, *fqdn = NULL;
const char *node;
- size_t hostname_len = 0;
*res = NULL;
if (!nodename && !servname)
@@ -6709,16 +6724,20 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
@@ -6794,13 +6810,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;
+ fqdn = get_fqdn();
+ if (!fqdn)
+ {
+ HeapFree(GetProcessHeap(), 0, hostname);
+ return WSA_NOT_ENOUGH_MEMORY;
+ }
+
if (!nodename)
node = NULL;
else if (!nodename[0])
- {
- if (!(fqdn = get_fqdn())) return WSA_NOT_ENOUGH_MEMORY;
- node = fqdn;
- }
+ node = hostname;
else
{
node = nodename;
@@ -6733,6 +6752,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
@@ -6813,7 +6836,13 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
if (node[0] == '[' && (close_bracket = strchr(node + 1, ']')))
{
nodeV6 = HeapAlloc(GetProcessHeap(), 0, close_bracket - node);
if (!nodeV6)
{
- if (!nodeV6) return WSA_NOT_ENOUGH_MEMORY;
+ if (!nodeV6)
+ {
+ HeapFree(GetProcessHeap(), 0, hostname);
HeapFree(GetProcessHeap(), 0, fqdn);
return WSA_NOT_ENOUGH_MEMORY;
}
@@ -6762,6 +6782,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
+ HeapFree(GetProcessHeap(), 0, fqdn);
+ return WSA_NOT_ENOUGH_MEMORY;
+ }
+
lstrcpynA(nodeV6, node + 1, close_bracket - node);
node = nodeV6;
}
@@ -6840,6 +6869,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
if (punixhints->ai_socktype < 0)
{
SetLastError(WSAESOCKTNOSUPPORT);
@@ -88,17 +92,18 @@ index 4d2afa946b7..ed1ca2f44b9 100644
HeapFree(GetProcessHeap(), 0, fqdn);
HeapFree(GetProcessHeap(), 0, nodeV6);
return SOCKET_ERROR;
@@ -6787,7 +6808,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
@@ -6864,7 +6894,8 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
/* getaddrinfo(3) is thread safe, no need to wrap in CS */
result = getaddrinfo(node, servname, punixhints, &unixaires);
if (result && (!hints || !(hints->ai_flags & WS_AI_NUMERICHOST))
- && node && (!strcmp(fqdn, node) || (!strncmp(fqdn, node, hostname_len) && !node[hostname_len])))
- if (result && (!hints || !(hints->ai_flags & WS_AI_NUMERICHOST)) && node)
+ if (result && (!hints || !(hints->ai_flags & WS_AI_NUMERICHOST))
+ && node && (!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
@@ -6796,6 +6817,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
result = getaddrinfo(NULL, servname ? servname : "0", punixhints, &unixaires);
if (!fqdn && !(fqdn = get_fqdn()))
{
@@ -6881,6 +6912,7 @@ int WINAPI WS_getaddrinfo(LPCSTR nodename, LPCSTR servname, const struct WS_addr
}
}
TRACE("%s, %s %p -> %p %d\n", debugstr_a(nodename), debugstr_a(servname), hints, res, result);
+ HeapFree(GetProcessHeap(), 0, hostname);
@@ -106,5 +111,5 @@ index 4d2afa946b7..ed1ca2f44b9 100644
HeapFree(GetProcessHeap(), 0, nodeV6);
--
2.27.0
2.28.0