ws2_32: Cope with buggy apps passing setsockopt optval as a value instead of a pointer.

This commit is contained in:
Kai Blin 2007-11-12 11:42:28 +01:00 committed by Alexandre Julliard
parent 0fade3c139
commit d35c13c621
2 changed files with 17 additions and 1 deletions

View File

@ -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:

View File

@ -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);
}