ws2_32: Cope with buggy apps passing setsockopt optval as a value instead of a pointer.
This commit is contained in:
parent
0fade3c139
commit
d35c13c621
|
@ -2812,6 +2812,13 @@ int WINAPI WS_setsockopt(SOCKET s, int level, int optname,
|
|||
TRACE("socket: %04lx, level 0x%x, name 0x%x, ptr %p, len %d\n",
|
||||
s, level, optname, optval, optlen);
|
||||
|
||||
/* some broken apps pass the value directly instead of a pointer to it */
|
||||
if(IS_INTRESOURCE(optval))
|
||||
{
|
||||
SetLastError(WSAEFAULT);
|
||||
return SOCKET_ERROR;
|
||||
}
|
||||
|
||||
switch(level)
|
||||
{
|
||||
case WS_SOL_SOCKET:
|
||||
|
|
|
@ -850,7 +850,7 @@ LINGER linger_testvals[] = {
|
|||
static void test_set_getsockopt(void)
|
||||
{
|
||||
SOCKET s;
|
||||
int i, err;
|
||||
int i, err, lasterr;
|
||||
int timeout;
|
||||
LINGER lingval;
|
||||
int size;
|
||||
|
@ -889,6 +889,15 @@ static void test_set_getsockopt(void)
|
|||
lingval.l_onoff, lingval.l_linger,
|
||||
linger_testvals[i].l_onoff, linger_testvals[i].l_linger);
|
||||
}
|
||||
/* Test for erroneously passing a value instead of a pointer as optval */
|
||||
size = sizeof(char);
|
||||
err = setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)1, size);
|
||||
ok(err == SOCKET_ERROR, "setsockopt with optval being a value passed "
|
||||
"instead of failing.\n");
|
||||
lasterr = WSAGetLastError();
|
||||
ok(lasterr == WSAEFAULT, "setsockopt with optval being a value "
|
||||
"returned 0x%08x, not WSAEFAULT(0x%08x)\n",
|
||||
lasterr, WSAEFAULT);
|
||||
closesocket(s);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue