mirror of
https://github.com/reactos/reactos.git
synced 2025-06-06 09:50:43 +00:00
[MSAFD][WS2_32] Better WSASocket parameters check
CORE-12104 svn path=/trunk/; revision=73068
This commit is contained in:
parent
e75da19bb3
commit
9817764e06
2 changed files with 54 additions and 10 deletions
|
@ -95,13 +95,33 @@ WSPSocket(int AddressFamily,
|
||||||
Protocol = SharedData->Protocol;
|
Protocol = SharedData->Protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AddressFamily == AF_UNSPEC && SocketType == 0 && Protocol == 0)
|
if (lpProtocolInfo)
|
||||||
|
{
|
||||||
|
if (lpProtocolInfo->iAddressFamily && AddressFamily <= 0)
|
||||||
|
AddressFamily = lpProtocolInfo->iAddressFamily;
|
||||||
|
if (lpProtocolInfo->iSocketType && SocketType <= 0)
|
||||||
|
SocketType = lpProtocolInfo->iSocketType;
|
||||||
|
if (lpProtocolInfo->iProtocol && Protocol <= 0)
|
||||||
|
Protocol = lpProtocolInfo->iProtocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FIXME: AF_NETDES should be AF_MAX */
|
||||||
|
if (AddressFamily < AF_UNSPEC || AddressFamily > AF_NETDES)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
|
if (SocketType < 0 && SocketType > SOCK_SEQPACKET)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
|
if (Protocol < 0 && Protocol > IPPROTO_MAX)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
|
/* when no protocol and socket type are specified the first entry
|
||||||
|
* from WSAEnumProtocols that has the flag PFL_MATCHES_PROTOCOL_ZERO
|
||||||
|
* is returned */
|
||||||
|
if (SocketType == 0 && Protocol == 0 && lpProtocolInfo && (lpProtocolInfo->dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO) == 0)
|
||||||
return WSAEINVAL;
|
return WSAEINVAL;
|
||||||
|
|
||||||
/* Set the defaults */
|
/* Set the defaults */
|
||||||
if (AddressFamily == AF_UNSPEC)
|
|
||||||
AddressFamily = AF_INET;
|
|
||||||
|
|
||||||
if (SocketType == 0)
|
if (SocketType == 0)
|
||||||
{
|
{
|
||||||
switch (Protocol)
|
switch (Protocol)
|
||||||
|
@ -117,8 +137,7 @@ WSPSocket(int AddressFamily,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
TRACE("Unknown Protocol (%d). We will try SOCK_STREAM.\n", Protocol);
|
TRACE("Unknown Protocol (%d). We will try SOCK_STREAM.\n", Protocol);
|
||||||
SocketType = SOCK_STREAM;
|
return WSAEINVAL;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,11 +156,13 @@ WSPSocket(int AddressFamily,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
TRACE("Unknown SocketType (%d). We will try IPPROTO_TCP.\n", SocketType);
|
TRACE("Unknown SocketType (%d). We will try IPPROTO_TCP.\n", SocketType);
|
||||||
Protocol = IPPROTO_TCP;
|
return WSAEINVAL;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (AddressFamily == AF_UNSPEC)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
/* Get Helper Data and Transport */
|
/* Get Helper Data and Transport */
|
||||||
Status = SockGetTdiName (&AddressFamily,
|
Status = SockGetTdiName (&AddressFamily,
|
||||||
&SocketType,
|
&SocketType,
|
||||||
|
|
|
@ -490,6 +490,20 @@ WsTcGetEntryFromTriplet(IN PTCATALOG Catalog,
|
||||||
/* Assume failure */
|
/* Assume failure */
|
||||||
*CatalogEntry = NULL;
|
*CatalogEntry = NULL;
|
||||||
|
|
||||||
|
/* Params can't be all wildcards */
|
||||||
|
if (af == AF_UNSPEC && type == 0 && protocol == 0)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
|
/* FIXME: AF_NETDES should be AF_MAX */
|
||||||
|
if (af < AF_UNSPEC || af > AF_NETDES)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
|
if (type < 0 && type > SOCK_SEQPACKET)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
|
if (protocol < 0 && protocol > IPPROTO_MAX)
|
||||||
|
return WSAEINVAL;
|
||||||
|
|
||||||
/* Lock the catalog */
|
/* Lock the catalog */
|
||||||
WsTcLock();
|
WsTcLock();
|
||||||
|
|
||||||
|
@ -527,6 +541,13 @@ WsTcGetEntryFromTriplet(IN PTCATALOG Catalog,
|
||||||
Entry->ProtocolInfo.iProtocolMaxOffset) >= protocol)) ||
|
Entry->ProtocolInfo.iProtocolMaxOffset) >= protocol)) ||
|
||||||
(protocol == 0))
|
(protocol == 0))
|
||||||
{
|
{
|
||||||
|
/* Check that if type and protocol are 0 provider entry has PFL_MATCHES_PROTOCOL_ZERO flag set */
|
||||||
|
if (type == 0 && protocol == 0 && (Entry->ProtocolInfo.dwProviderFlags & PFL_MATCHES_PROTOCOL_ZERO) == 0)
|
||||||
|
{
|
||||||
|
ErrorCode = WSAEPROTONOSUPPORT;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if it doesn't already have a provider */
|
/* Check if it doesn't already have a provider */
|
||||||
if (!Entry->Provider)
|
if (!Entry->Provider)
|
||||||
{
|
{
|
||||||
|
@ -550,11 +571,13 @@ WsTcGetEntryFromTriplet(IN PTCATALOG Catalog,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (ErrorCode != WSAEPROTONOSUPPORT)
|
||||||
ErrorCode = WSAESOCKTNOSUPPORT;
|
ErrorCode = WSAESOCKTNOSUPPORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (ErrorCode != WSAEPROTONOSUPPORT && ErrorCode != WSAESOCKTNOSUPPORT)
|
||||||
ErrorCode = WSAEAFNOSUPPORT;
|
ErrorCode = WSAEAFNOSUPPORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue