ws2_32: ConnectEx should not work on unbound socket.

This commit is contained in:
Bruno Jesus 2013-09-20 00:14:27 -03:00 committed by Alexandre Julliard
parent 128bfdf6da
commit 68377494c6
2 changed files with 14 additions and 2 deletions

View File

@ -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)
{

View File

@ -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)
{