ws2_32: ConnectEx should not work on unbound socket
Bruno Jesus
00cpxxx at gmail.com
Thu Sep 19 22:14:27 CDT 2013
-------------- next part --------------
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 2cb077e..45166de 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2726,6 +2726,8 @@ static BOOL WINAPI WS2_ConnectEx(SOCKET s, const struct WS_sockaddr* name, int n
PVOID sendBuf, DWORD sendBufLen, LPDWORD sent, LPOVERLAPPED ov)
{
int fd, ret, status;
+ union generic_unix_sockaddr uaddr;
+ socklen_t uaddrlen = sizeof(uaddr);
if (!ov)
{
@@ -2743,7 +2745,17 @@ static BOOL WINAPI WS2_ConnectEx(SOCKET s, const struct WS_sockaddr* name, int n
TRACE("socket %04lx, ptr %p %s, length %d, sendptr %p, len %d, ov %p\n",
s, name, debugstr_sockaddr(name), namelen, sendBuf, sendBufLen, ov);
- /* FIXME: technically the socket has to be bound */
+ if (getsockname(fd, &uaddr.addr, &uaddrlen) != 0)
+ {
+ SetLastError(wsaErrno());
+ return FALSE;
+ }
+ else if (!is_sockaddr_bound(&uaddr.addr, uaddrlen))
+ {
+ SetLastError(WSAEINVAL);
+ return FALSE;
+ }
+
ret = do_connect(fd, name, namelen);
if (ret == 0)
{
diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c
index b77bb3c..c1d6956 100644
--- a/dlls/ws2_32/tests/sock.c
+++ b/dlls/ws2_32/tests/sock.c
@@ -5097,7 +5097,7 @@ static void test_ConnectEx(void)
"returned %d + errno %d\n", bret, WSAGetLastError());
bret = pConnectEx(connector, (struct sockaddr*)&address, addrlen, NULL, 0, &bytesReturned, &overlapped);
- todo_wine ok(bret == FALSE && WSAGetLastError() == WSAEINVAL, "ConnectEx on a unbound socket "
+ ok(bret == FALSE && WSAGetLastError() == WSAEINVAL, "ConnectEx on a unbound socket "
"returned %d + errno %d\n", bret, WSAGetLastError());
if (bret == TRUE || WSAGetLastError() != WSAEINVAL)
{
More information about the wine-patches
mailing list