Index: winetests/ntdll/rtl.c =================================================================== --- winetests/ntdll/rtl.c (revision 65739) +++ winetests/ntdll/rtl.c (working copy) @@ -89,6 +89,7 @@ static CHAR * (WINAPI *pRtlIpv4AddressToStringA)(const IN_ADDR *, LPSTR); static NTSTATUS (WINAPI *pRtlIpv4AddressToStringExA)(const IN_ADDR *, USHORT, LPSTR, PULONG); static NTSTATUS (WINAPI *pRtlIpv4StringToAddressA)(PCSTR, BOOLEAN, PCSTR *, IN_ADDR *); +static NTSTATUS (WINAPI *pRtlIpv4StringToAddressExA)(PCTSTR, BOOLEAN, IN_ADDR *, PUSHORT); static NTSTATUS (WINAPI *pLdrAddRefDll)(ULONG, HMODULE); static NTSTATUS (WINAPI *pLdrLockLoaderLock)(ULONG, ULONG*, ULONG_PTR*); static NTSTATUS (WINAPI *pLdrUnlockLoaderLock)(ULONG, ULONG_PTR); @@ -136,6 +137,7 @@ pRtlIpv4AddressToStringA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringA"); pRtlIpv4AddressToStringExA = (void *)GetProcAddress(hntdll, "RtlIpv4AddressToStringExA"); pRtlIpv4StringToAddressA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressA"); + pRtlIpv4StringToAddressExA = (void *)GetProcAddress(hntdll, "RtlIpv4StringToAddressExA"); pLdrAddRefDll = (void *)GetProcAddress(hntdll, "LdrAddRefDll"); pLdrLockLoaderLock = (void *)GetProcAddress(hntdll, "LdrLockLoaderLock"); pLdrUnlockLoaderLock = (void *)GetProcAddress(hntdll, "LdrUnlockLoaderLock"); @@ -1492,6 +1494,103 @@ } } +static void test_RtlIpv4StringToAddressEx(void) +{ + NTSTATUS res; + IN_ADDR ip, expected_ip; + USHORT port; + struct + { + PCSTR address; + NTSTATUS res; + int ip[4]; + USHORT port; + } tests[] = + { + { "", STATUS_INVALID_PARAMETER, { -1 }, 0xdead }, + { " ", STATUS_INVALID_PARAMETER, { -1 }, 0xdead }, + { "1.1.1.1:", STATUS_INVALID_PARAMETER, { 1, 1, 1, 1 }, 0xdead }, + { "1.1.1.1+", STATUS_INVALID_PARAMETER, { 1, 1, 1, 1 }, 0xdead }, + { "1.1.1.1:1", STATUS_SUCCESS, { 1, 1, 1, 1 }, 0x100 }, + { "0.0.0.0:0", STATUS_INVALID_PARAMETER, { 0, 0, 0, 0 }, 0xdead }, + { "0.0.0.0:1", STATUS_SUCCESS, { 0, 0, 0, 0 }, 0x100 }, + { "1.2.3.4:65535", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 }, + { "1.2.3.4:65536", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4:0xffff", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 }, + { "1.2.3.4:0XfFfF", STATUS_SUCCESS, { 1, 2, 3, 4 }, 65535 }, + { "1.2.3.4:011064", STATUS_SUCCESS, { 1, 2, 3, 4 }, 0x3412 }, + { "1.2.3.4:1234a", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4:1234+", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4: 1234", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + { "1.2.3.4:\t1234", STATUS_INVALID_PARAMETER, { 1, 2, 3, 4 }, 0xdead }, + }; + const int testcount = sizeof(tests) / sizeof(tests[0]); + int i, Strict; + + if (!pRtlIpv4StringToAddressExA) + { + skip("RtlIpv4StringToAddressEx not available\n"); + return; + } + + // do not crash, and do not touch the ip / port. + ip.S_un.S_addr = 0xabababab; + port = 0xdead; + res = pRtlIpv4StringToAddressExA(NULL, FALSE, &ip, &port); + ok(res == STATUS_INVALID_PARAMETER, + "[null address] res = 0x%08x, expected 0x%08x\n", + res, STATUS_INVALID_PARAMETER); + ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip.S_un.S_addr); + ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port); + + port = 0xdead; + res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, NULL, &port); + ok(res == STATUS_INVALID_PARAMETER, + "[null ip] res = 0x%08x, expected 0x%08x\n", + res, STATUS_INVALID_PARAMETER); + ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port); + + ip.S_un.S_addr = 0xabababab; + port = 0xdead; + res = pRtlIpv4StringToAddressExA("1.1.1.1", FALSE, &ip, NULL); + ok(res == STATUS_INVALID_PARAMETER, + "[null port] res = 0x%08x, expected 0x%08x\n", + res, STATUS_INVALID_PARAMETER); + ok(ip.S_un.S_addr == 0xabababab, "RtlIpv4StringToAddressExA should not touch the ip!, ip == %x\n", ip.S_un.S_addr); + ok(port == 0xdead, "RtlIpv4StringToAddressExA should not touch the port!, port == %x\n", port); + + for (i = 0; i < testcount; i++) + { + // Strict is only relevant for the ip address, so make sure that it does not influence the port + for (Strict = 0; Strict < 2; Strict++) + { + ip.S_un.S_addr = 0xabababab; + port = 0xdead; + res = pRtlIpv4StringToAddressExA(tests[i].address, Strict, &ip, &port); + ok(res == tests[i].res, + "[%s] res = 0x%08x, expected 0x%08x\n", + tests[i].address, res, tests[i].res); + if (tests[i].ip[0] == -1) + { + expected_ip.S_un.S_addr = 0xabababab; + } + else + { + expected_ip.S_un.S_un_b.s_b1 = tests[i].ip[0]; + expected_ip.S_un.S_un_b.s_b2 = tests[i].ip[1]; + expected_ip.S_un.S_un_b.s_b3 = tests[i].ip[2]; + expected_ip.S_un.S_un_b.s_b4 = tests[i].ip[3]; + } + ok(ip.S_un.S_addr == expected_ip.S_un.S_addr, + "[%s] ip = %08x, expected %08x\n", + tests[i].address, ip.S_un.S_addr, expected_ip.S_un.S_addr); + ok(port == tests[i].port, + "[%s] port = %u, expected %u\n", + tests[i].address, port, tests[i].port); + } + } +} + static void test_LdrAddRefDll(void) { HMODULE mod, mod2; @@ -1631,6 +1730,7 @@ test_RtlIpv4AddressToString(); test_RtlIpv4AddressToStringEx(); test_RtlIpv4StringToAddress(); + test_RtlIpv4StringToAddressEx(); test_LdrAddRefDll(); test_LdrLockLoaderLock(); }