[MSAFD]
authorCameron Gutman <aicommander@gmail.com>
Mon, 7 Jun 2010 01:50:26 +0000 (01:50 +0000)
committerCameron Gutman <aicommander@gmail.com>
Mon, 7 Jun 2010 01:50:26 +0000 (01:50 +0000)
- Fix 2 more callers who don't pass a valid lpErrno pointer
- Check the return value of WSPSocket
- Return WSAEWOULDBLOCK if there are no connections that can be accepted instead of silently returning 0 which is not INVALID_SOCKET so the caller treats it as a valid socket pointer and passes it to other functions which caused wide-spread mayhem since we never checked whether the socket handle the caller passed was valid until my last commit

svn path=/trunk/; revision=47652

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

index 1ea4ce7..f06b0a5 100644 (file)
@@ -1102,12 +1102,17 @@ WSPAccept(SOCKET Handle,
     Timeout.tv_sec=0;
     Timeout.tv_usec=0;
 
-    WSPSelect(0, &ReadSet, NULL, NULL, &Timeout, NULL);
+    if (WSPSelect(0, &ReadSet, NULL, NULL, &Timeout, lpErrno) == SOCKET_ERROR)
+    {
+        NtClose(SockEvent);
+        return INVALID_SOCKET;
+    }
 
     if (ReadSet.fd_array[0] != Socket->Handle)
     {
         NtClose(SockEvent);
-        return 0;
+        *lpErrno = WSAEWOULDBLOCK;
+        return INVALID_SOCKET;
     }
 
     /* Send IOCTL */
@@ -1345,7 +1350,9 @@ WSPAccept(SOCKET Handle,
                               &ProtocolInfo,
                               GroupID,
                               Socket->SharedData.CreateFlags,
-                              NULL);
+                              lpErrno);
+    if (AcceptSocket == INVALID_SOCKET)
+        return INVALID_SOCKET;
 
     /* Set up the Accept Structure */
     AcceptData.ListenHandle = (HANDLE)AcceptSocket;
index db26a36..557fdae 100644 (file)
@@ -51,7 +51,11 @@ WSPAsyncSelect(IN  SOCKET Handle,
     /* Deactive WSPEventSelect */
     if (Socket->SharedData.AsyncEvents)
     {
-        WSPEventSelect(Handle, NULL, 0, NULL);
+        if (WSPEventSelect(Handle, NULL, 0, lpErrno) == SOCKET_ERROR)
+        {
+            HeapFree(GetProcessHeap(), 0, AsyncData);
+            return SOCKET_ERROR;
+        }
     }
 
     /* Create the Asynch Thread if Needed */