Commit 9d9e1cc9 authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32: Ensure an IPv6 is not recognized as IPv4 in WSAStringToAddress.

parent 127aa62a
......@@ -7081,6 +7081,12 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
ptrPort = strchr(workBuffer, ':');
if(ptrPort)
{
/* User may have entered an IPv6 and asked to parse as IPv4 */
if(strchr(ptrPort + 1, ':'))
{
res = WSAEINVAL;
break;
}
((LPSOCKADDR_IN)lpAddress)->sin_port = htons(atoi(ptrPort+1));
*ptrPort = '\0';
}
......
......@@ -3010,6 +3010,7 @@ static void test_WSAStringToAddressA(void)
CHAR address6[] = "::1";
CHAR address7[] = "[::1]";
CHAR address8[] = "[::1]:65535";
CHAR address9[] = "2001::1";
len = 0;
sockaddr.sin_family = AF_INET;
......@@ -3093,6 +3094,12 @@ static void test_WSAStringToAddressA(void)
(ret == SOCKET_ERROR && GLE == WSAEINVAL),
"WSAStringToAddressA() failed for IPv6 address: %d\n", GLE);
len = sizeof(sockaddr);
ret = WSAStringToAddressA( address9, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
GLE = WSAGetLastError();
ok( (ret == SOCKET_ERROR && GLE == WSAEINVAL),
"WSAStringToAddressA() should have failed with %d\n", GLE );
}
static void test_WSAStringToAddressW(void)
......@@ -3113,6 +3120,7 @@ static void test_WSAStringToAddressW(void)
WCHAR address6[] = {':',':','1','\0'};
WCHAR address7[] = {'[',':',':','1',']','\0'};
WCHAR address8[] = {'[',':',':','1',']',':','6','5','5','3','5','\0'};
WCHAR address9[] = {'2','0','0','1',':',':','1','\0'};
len = 0;
sockaddr.sin_family = AF_INET;
......@@ -3209,6 +3217,12 @@ static void test_WSAStringToAddressW(void)
(ret == SOCKET_ERROR && GLE == WSAEINVAL),
"WSAStringToAddressW() failed for IPv6 address: %d\n", GLE);
len = sizeof(sockaddr);
ret = WSAStringToAddressW( address9, AF_INET, NULL, (SOCKADDR*)&sockaddr, &len );
GLE = WSAGetLastError();
ok( (ret == SOCKET_ERROR && GLE == WSAEINVAL),
"WSAStringToAddressW() should have failed with %d\n", GLE );
}
static DWORD WINAPI SelectReadThread(void *param)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment