From: Jinoh Kang jinoh.kang.kr@gmail.com
test_reuseaddr and test_exclusiveaddruse bind to the wildcard address (0.0.0.0 or [::]). This may trigger a firewall alert on Windows 7, and the alert UI window may interfere with user32:msg tests.
Fix this by trying to disable the firewall, and skipping the wildcard address tests if it fails.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53891 Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54202 --- dlls/ws2_32/tests/Makefile.in | 2 +- dlls/ws2_32/tests/sock.c | 67 ++++++++++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 5 deletions(-)
diff --git a/dlls/ws2_32/tests/Makefile.in b/dlls/ws2_32/tests/Makefile.in index b1b10c1636e..f9b4ac0d556 100644 --- a/dlls/ws2_32/tests/Makefile.in +++ b/dlls/ws2_32/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = ws2_32.dll -IMPORTS = iphlpapi ws2_32 user32 +IMPORTS = iphlpapi ws2_32 user32 ole32 oleaut32 advapi32
C_SRCS = \ afd.c \ diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 5e5916373f1..c440cf78d03 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -23,6 +23,7 @@
#include <ntstatus.h> #define WIN32_NO_STATUS +#define COBJMACROS #include <winsock2.h> #include <windows.h> #include <winternl.h> @@ -33,7 +34,9 @@ #include <mswsock.h> #include <mstcpip.h> #include <stdio.h> +#include <initguid.h> #include "wine/test.h" +#include "wine/test_fw.h"
#define MAX_CLIENTS 4 /* Max number of clients */ #define FIRST_CHAR 'A' /* First character in transferred pattern */ @@ -162,6 +165,35 @@ static GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; static SOCKET setup_server_socket(struct sockaddr_in *addr, int *len); static SOCKET setup_connector_socket(const struct sockaddr_in *addr, int len, BOOL nonblock);
+static BOOL is_loopback_addr(const struct sockaddr *saddr) +{ + if (saddr->sa_family == AF_INET) + { + const struct sockaddr_in *sa_in = (const struct sockaddr_in *)saddr; + return sa_in->sin_addr.s_addr == htonl(INADDR_LOOPBACK); + } + + if (saddr->sa_family == AF_INET6) + { + static const BYTE in6_loopback[16] = + { + /* ::1 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + }; + static const BYTE in6_loopback_v4mapped[16] = + { + /* ::ffff:127.0.0.1 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01, + }; + const struct sockaddr_in6 *sa_in6 = (const struct sockaddr_in6 *)saddr; + return memcmp(&sa_in6->sin6_addr, in6_loopback, 16) == 0 || + memcmp(&sa_in6->sin6_addr, in6_loopback_v4mapped, 16) == 0; + } + + ok(0, "unexpected family %d\n", saddr->sa_family); + return FALSE; +} + static void tcp_socketpair_flags(SOCKET *src, SOCKET *dst, DWORD flags) { SOCKET server = INVALID_SOCKET; @@ -2013,7 +2045,7 @@ static void test_set_getsockopt(void) } }
-static void test_reuseaddr(void) +static void test_reuseaddr(BOOL loopback_only) { static struct sockaddr_in6 saddr_in6_any, saddr_in6_loopback; static struct sockaddr_in6 saddr_in6_any_v4mapped, saddr_in6_loopback_v4mapped; @@ -2136,6 +2168,12 @@ static void test_reuseaddr(void) winetest_pop_context(); }
+ if (loopback_only) + { + skip("Loopback only mode: skipping tests with any addr\n"); + return; + } + for (i = 0; i < ARRAY_SIZE(tests); ++i) { winetest_push_context("test with any %u", i); @@ -2229,7 +2267,7 @@ static void test_reuseaddr(void) } }
-static void test_exclusiveaddruse(void) +static void test_exclusiveaddruse(BOOL loopback_only) { static struct sockaddr_in6 saddr_in6_any, saddr_in6_loopback; static struct sockaddr_in6 saddr_in6_any_v4mapped, saddr_in6_loopback_v4mapped; @@ -2410,6 +2448,13 @@ static void test_exclusiveaddruse(void) { SOCKET s[2];
+ if (loopback_only && !(is_loopback_addr(tests_exclusive[i].s[0].addr) && + is_loopback_addr(tests_exclusive[i].s[1].addr))) + { + skip("Loopback only mode: skipping test %d\n", i); + continue; + } + winetest_push_context("test %u", i);
for (j = 0; j < 2; ++j) @@ -13695,6 +13740,7 @@ static void test_connect_udp(void)
START_TEST( sock ) { + BOOL fw_set_ok; int i;
/* Leave these tests at the beginning. They depend on WSAStartup not having been @@ -13705,8 +13751,21 @@ START_TEST( sock ) Init();
test_set_getsockopt(); - test_reuseaddr(); - test_exclusiveaddruse(); + + /* Keep the firewall-exempt region as small as possible. + * + * We don't want to skip _all_ tests if the firewall initialization fails. + * It's useful to test socket behaviour as an unprivileged process even if + * the firewall is enabled. + */ + fw_set_ok = winetest_set_firewall( L"ws2_32_test", WINETEST_FW_APP_ADD ); + test_reuseaddr(!fw_set_ok); + test_exclusiveaddruse(!fw_set_ok); + if (fw_set_ok) + { + winetest_set_firewall( L"ws2_32_test", WINETEST_FW_APP_REMOVE ); + } + test_ip_pktinfo(); test_ipv4_cmsg(); test_ipv6_cmsg();