ws2_32: Return WSAEINVAL if "out_size" is smaller than the minimum size for SIO_ADDRESS_LIST_QUERY.

This commit is contained in:
Henri Verbeet 2014-10-03 09:19:22 +02:00 committed by Alexandre Julliard
parent 4e6ebd633a
commit b914a6461b
2 changed files with 19 additions and 0 deletions

View file

@ -3937,6 +3937,13 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
return SOCKET_ERROR;
}
if (out_size && out_size < FIELD_OFFSET(SOCKET_ADDRESS_LIST, Address[0]))
{
*ret_size = 0;
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
if (GetAdaptersInfo(NULL, &size) == ERROR_BUFFER_OVERFLOW)
{
IP_ADAPTER_INFO *p, *table = HeapAlloc(GetProcessHeap(), 0, size);

View file

@ -7498,6 +7498,18 @@ static void test_address_list_query(void)
ok(ret == SOCKET_ERROR, "Got unexpected ret %d.\n", ret);
ok(WSAGetLastError() == WSAEFAULT, "Got unexpected error %d.\n", WSAGetLastError());
bytes_returned = 0xdeadbeef;
ret = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, address_list, 1, &bytes_returned, NULL, NULL);
ok(ret == SOCKET_ERROR, "Got unexpected ret %d.\n", ret);
ok(WSAGetLastError() == WSAEINVAL, "Got unexpected error %d.\n", WSAGetLastError());
ok(bytes_returned == 0, "Got unexpected bytes_returned %u.\n", bytes_returned);
ret = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, address_list,
FIELD_OFFSET(SOCKET_ADDRESS_LIST, Address[0]), &bytes_returned, NULL, NULL);
ok(ret == SOCKET_ERROR, "Got unexpected ret %d.\n", ret);
ok(WSAGetLastError() == WSAEFAULT, "Got unexpected error %d.\n", WSAGetLastError());
ok(bytes_returned == size, "Got unexpected bytes_returned %u, expected %u.\n", bytes_returned, size);
HeapFree(GetProcessHeap(), 0, address_list);
closesocket(s);
}