Bruno Jesus : ws2_32: Fix WSAStringToAddress parsing for IPv6.

Alexandre Julliard julliard at winehq.org
Thu Jul 20 12:11:27 CDT 2017


Module: wine
Branch: stable
Commit: 6b72103758a84b6ccbfa2e9837c9acc43ed87c1a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6b72103758a84b6ccbfa2e9837c9acc43ed87c1a

Author: Bruno Jesus <bjesus at codeweavers.com>
Date:   Thu Mar  2 22:21:44 2017 -0300

ws2_32: Fix WSAStringToAddress parsing for IPv6.

Signed-off-by: Bruno Jesus <bjesus at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit b60cd6830848431e359196bb1d801e93d0952fdf)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/ws2_32/socket.c     | 36 ++++++++++++++++++------------------
 dlls/ws2_32/tests/sock.c |  4 ----
 2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 4977bbf..e6ff524 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -8266,10 +8266,6 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
             ((LPSOCKADDR_IN)lpAddress)->sin_port = htons(atoi(ptrPort+1));
             *ptrPort = '\0';
         }
-        else
-        {
-            ((LPSOCKADDR_IN)lpAddress)->sin_port = 0;
-        }
 
         if(inet_aton(workBuffer, &inetaddr) > 0)
         {
@@ -8280,11 +8276,12 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
             res = WSAEINVAL;
 
         break;
-
     }
     case WS_AF_INET6:
     {
         struct in6_addr inetaddr;
+        char *ptrAddr = workBuffer;
+
         /* If lpAddressLength is too small, tell caller the size we need */
         if (*lpAddressLength < sizeof(SOCKADDR_IN6))
         {
@@ -8298,24 +8295,27 @@ INT WINAPI WSAStringToAddressA(LPSTR AddressString,
 
         ((LPSOCKADDR_IN6)lpAddress)->sin6_family = WS_AF_INET6;
 
-        /* This one is a bit tricky. An IPv6 address contains colons, so the
-         * check from IPv4 doesn't work like that. However, IPv6 addresses that
-         * contain a port are written with braces like [fd12:3456:7890::1]:12345
-         * so what we will do is to look for ']', check if the next char is a
-         * colon, and if it is, parse the port as in IPv4. */
+        /* Valid IPv6 addresses can also be surrounded by [ ], and in this case
+         * a port number may follow after like in [fd12:3456:7890::1]:12345
+         * We need to cut the brackets and find the port if any. */
 
-        ptrPort = strchr(workBuffer, ']');
-        if(ptrPort && *(++ptrPort) == ':')
+        if(*workBuffer == '[')
         {
-            ((LPSOCKADDR_IN6)lpAddress)->sin6_port = htons(atoi(ptrPort+1));
+            ptrPort = strchr(workBuffer, ']');
+            if (!ptrPort)
+            {
+                SetLastError(WSAEINVAL);
+                return SOCKET_ERROR;
+            }
+
+            if (ptrPort[1] == ':')
+                ((LPSOCKADDR_IN6)lpAddress)->sin6_port = htons(atoi(ptrPort + 2));
+
             *ptrPort = '\0';
-        }
-        else
-        {
-            ((LPSOCKADDR_IN6)lpAddress)->sin6_port = 0;
+            ptrAddr = workBuffer + 1;
         }
 
-        if(inet_pton(AF_INET6, workBuffer, &inetaddr) > 0)
+        if(inet_pton(AF_INET6, ptrAddr, &inetaddr) > 0)
         {
             memcpy(&((LPSOCKADDR_IN6)lpAddress)->sin6_addr, &inetaddr,
                     sizeof(struct in6_addr));
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index f673688..8df3f5c 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -3354,7 +3354,6 @@ static void test_WSAStringToAddressA(void)
     ret = WSAStringToAddressA( address7, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
             &len );
     GLE = WSAGetLastError();
-todo_wine
     ok( ret == 0, "WSAStringToAddressA() failed for IPv6 address: %d\n", GLE);
 
     len = sizeof(sockaddr6);
@@ -3364,7 +3363,6 @@ todo_wine
     ret = WSAStringToAddressA( address8, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
             &len );
     GLE = WSAGetLastError();
-todo_wine
     ok( ret == 0 && sockaddr6.sin6_port == 0xffff,
         "WSAStringToAddressA() failed for IPv6 address: %d\n", GLE);
 
@@ -3496,7 +3494,6 @@ static void test_WSAStringToAddressW(void)
     ret = WSAStringToAddressW( address7, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
             &len );
     GLE = WSAGetLastError();
-todo_wine
     ok( ret == 0, "WSAStringToAddressW() failed for IPv6 address: %d\n", GLE);
 
     len = sizeof(sockaddr6);
@@ -3506,7 +3503,6 @@ todo_wine
     ret = WSAStringToAddressW( address8, AF_INET6, NULL, (SOCKADDR*)&sockaddr6,
             &len );
     GLE = WSAGetLastError();
-todo_wine
     ok( ret == 0 && sockaddr6.sin6_port == 0xffff,
         "WSAStringToAddressW() failed for IPv6 address: %d\n", GLE);
 




More information about the wine-cvs mailing list