Commit 0298165b authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

ws2_32: Filter invalid socket parameters and return the appropriate error.

parent 35e54fa5
......@@ -5868,6 +5868,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
{
SOCKET ret;
DWORD err;
int unixaf, unixtype;
/*
FIXME: The "advanced" parameters of WSASocketW (lpProtocolInfo,
......@@ -5913,14 +5914,50 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
}
}
/* convert the socket family and type */
af = convert_af_w2u(af);
type = convert_socktype_w2u(type);
/* convert the socket family, type and protocol */
unixaf = convert_af_w2u(af);
unixtype = convert_socktype_w2u(type);
protocol = convert_proto_w2u(protocol);
if (unixaf == AF_UNSPEC) unixaf = -1;
/* filter invalid parameters */
if (protocol < 0)
{
/* the type could not be converted */
if (type && unixtype < 0)
{
err = WSAESOCKTNOSUPPORT;
goto done;
}
err = WSAEPROTONOSUPPORT;
goto done;
}
if (unixaf < 0)
{
/* both family and protocol can't be invalid */
if (protocol <= 0)
{
err = WSAEINVAL;
goto done;
}
/* family could not be converted and neither socket type */
if (unixtype < 0 && af >= 0)
{
err = WSAESOCKTNOSUPPORT;
goto done;
}
err = WSAEAFNOSUPPORT;
goto done;
}
SERVER_START_REQ( create_socket )
{
req->family = af;
req->type = type;
req->family = unixaf;
req->type = unixtype;
req->protocol = protocol;
req->access = GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE;
req->attributes = OBJ_INHERIT;
......@@ -5952,6 +5989,7 @@ SOCKET WINAPI WSASocketW(int af, int type, int protocol,
err = WSAEPROTONOSUPPORT;
}
done:
WARN("\t\tfailed, error %d!\n", err);
SetLastError(err);
return INVALID_SOCKET;
......
......@@ -1784,7 +1784,6 @@ static void test_WSASocket(void)
ok(WSASocketA(0, 0, 0, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
sock = WSASocketA(AF_INET, 0, 0, NULL, 0, 0);
......@@ -1811,10 +1810,21 @@ todo_wine
ok(WSASocketA(0, -1, 0, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
SetLastError(0xdeadbeef);
ok(WSASocketA(AF_INET, -1, 0, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
ok(err == WSAESOCKTNOSUPPORT, "Expected 10044, received %d\n", err);
SetLastError(0xdeadbeef);
ok(WSASocketA(AF_INET, 0, -1, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
SetLastError(0xdeadbeef);
ok(WSASocketA(0, -1, -1, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
......@@ -1824,7 +1834,6 @@ todo_wine
ok(WSASocketA(-1, SOCK_STREAM, IPPROTO_UDP, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
sock = WSASocketA(AF_INET, 0, IPPROTO_TCP, NULL, 0, 0);
......@@ -1835,14 +1844,12 @@ todo_wine
ok(WSASocketA(0, SOCK_STREAM, 0, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
SetLastError(0xdeadbeef);
ok(WSASocketA(0, 0, 0xdead, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEPROTONOSUPPORT, "Expected 10043, received %d\n", err);
SetLastError(0xdeadbeef);
......@@ -1855,7 +1862,6 @@ todo_wine
ok(WSASocketA(0, 0xdead, 0, NULL, 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEINVAL, "Expected 10022, received %d\n", err);
sock = WSASocketA(0, 0, IPPROTO_TCP, NULL, 0, 0);
......@@ -1917,7 +1923,6 @@ todo_wine
ok(WSASocketA(0, 0, IPPROTO_UDP, &pi[0], 0, 0) == INVALID_SOCKET,
"WSASocketA should have failed\n");
err = WSAGetLastError();
todo_wine
ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
pi[0].iProtocol = 0;
......@@ -1932,7 +1937,6 @@ todo_wine
else
{
err = WSAGetLastError();
todo_wine
ok(err == WSAEAFNOSUPPORT, "Expected 10047, received %d\n", err);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment