[WS2_32] Add some parameters check for getsockname. Use value size for size check...
[reactos.git] / reactos / dll / win32 / ws2_32 / src / sockctrl.c
index 0aa512a..1bf9e82 100644 (file)
@@ -217,20 +217,28 @@ getsockname(IN SOCKET s,
         /* Get the Socket Context */
         if ((Socket = WsSockGetSocket(s)))
         {
-            /* Make the call */
-            Status = Socket->Provider->Service.lpWSPGetSockName(s,
-                                                                name,
-                                                                namelen,
-                                                                &ErrorCode);
+            if (name && namelen && (*namelen >= sizeof(*name)))
+            {
+                /* Make the call */
+                Status = Socket->Provider->Service.lpWSPGetSockName(s,
+                                                                    name,
+                                                                    namelen,
+                                                                    &ErrorCode);
 
-            /* Deference the Socket Context */
-            WsSockDereference(Socket);
+                /* Deference the Socket Context */
+                WsSockDereference(Socket);
 
-            /* Return Provider Value */
-            if (Status == ERROR_SUCCESS) return Status;
+                /* Return Provider Value */
+                if (Status == ERROR_SUCCESS) return Status;
 
-            /* If everything seemed fine, then the WSP call failed itself */
-            if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
+                /* If everything seemed fine, then the WSP call failed itself */
+                if (ErrorCode == NO_ERROR) ErrorCode = WSASYSCALLFAILURE;
+            }
+            else
+            {
+                /* name or namelen not valid */
+                ErrorCode = WSAEFAULT;
+            }
         }
         else
         {