[MSAFD] Add some parameters check for WSPBind. Inspired by results of bind test
authorPeter Hater <7element@mail.bg>
Fri, 26 May 2017 10:32:01 +0000 (10:32 +0000)
committerPeter Hater <7element@mail.bg>
Fri, 26 May 2017 10:32:01 +0000 (10:32 +0000)
svn path=/trunk/; revision=74668

reactos/dll/win32/msafd/misc/dllmain.c

index 2531bdf..7bd45bf 100644 (file)
@@ -860,6 +860,27 @@ WSPBind(SOCKET Handle,
        if (lpErrno) *lpErrno = WSAENOTSOCK;
        return SOCKET_ERROR;
     }
+    if (Socket->SharedData->State != SocketOpen)
+    {
+       if (lpErrno) *lpErrno = WSAEINVAL;
+       return SOCKET_ERROR;
+    }
+    if (!SocketAddress || SocketAddressLength < Socket->SharedData->SizeOfLocalAddress)
+    {
+        if (lpErrno) *lpErrno = WSAEINVAL;
+        return SOCKET_ERROR;
+    }
+
+    /* Get Address Information */
+    Socket->HelperData->WSHGetSockaddrType ((PSOCKADDR)SocketAddress,
+                                            SocketAddressLength,
+                                            &SocketInfo);
+
+    if (SocketInfo.AddressInfo == SockaddrAddressInfoBroadcast && !Socket->SharedData->Broadcast)
+    {
+       if (lpErrno) *lpErrno = WSAEADDRNOTAVAIL;
+       return SOCKET_ERROR;
+    }
 
     Status = NtCreateEvent(&SockEvent,
                            EVENT_ALL_ACCESS,
@@ -887,11 +908,6 @@ WSPBind(SOCKET Handle,
                    SocketAddress->sa_data,
                    SocketAddressLength - sizeof(SocketAddress->sa_family));
 
-    /* Get Address Information */
-    Socket->HelperData->WSHGetSockaddrType ((PSOCKADDR)SocketAddress,
-                                            SocketAddressLength,
-                                            &SocketInfo);
-
     /* Set the Share Type */
     if (Socket->SharedData->ExclusiveAddressUse)
     {