Commit 32724def authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ws2_32: Return an error if "out_buff" is NULL for SIO_ADDRESS_LIST_QUERY.

parent 3b1e8bf8
...@@ -3947,6 +3947,10 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID ...@@ -3947,6 +3947,10 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
if (GetAdaptersInfo(NULL, &size) == ERROR_BUFFER_OVERFLOW) if (GetAdaptersInfo(NULL, &size) == ERROR_BUFFER_OVERFLOW)
{ {
IP_ADAPTER_INFO *p, *table = HeapAlloc(GetProcessHeap(), 0, size); IP_ADAPTER_INFO *p, *table = HeapAlloc(GetProcessHeap(), 0, size);
SOCKET_ADDRESS_LIST *sa_list;
SOCKADDR_IN *sockaddr;
SOCKET_ADDRESS *sa;
unsigned int i;
DWORD num; DWORD num;
if (!table || GetAdaptersInfo(table, &size)) if (!table || GetAdaptersInfo(table, &size))
...@@ -3962,7 +3966,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID ...@@ -3962,7 +3966,7 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
total = sizeof(SOCKET_ADDRESS_LIST) + sizeof(SOCKET_ADDRESS) * (num - 1); total = sizeof(SOCKET_ADDRESS_LIST) + sizeof(SOCKET_ADDRESS) * (num - 1);
total += sizeof(SOCKADDR) * num; total += sizeof(SOCKADDR) * num;
if (total > out_size) if (total > out_size || !out_buff)
{ {
*ret_size = total; *ret_size = total;
HeapFree(GetProcessHeap(), 0, table); HeapFree(GetProcessHeap(), 0, table);
...@@ -3970,29 +3974,22 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID ...@@ -3970,29 +3974,22 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID
break; break;
} }
if (out_buff) sa_list = out_buff;
{ sa = sa_list->Address;
unsigned int i; sockaddr = (SOCKADDR_IN *)((char *)sa + num * sizeof(SOCKET_ADDRESS));
SOCKET_ADDRESS *sa; sa_list->iAddressCount = num;
SOCKET_ADDRESS_LIST *sa_list = out_buff;
SOCKADDR_IN *sockaddr;
sa = sa_list->Address;
sockaddr = (SOCKADDR_IN *)((char *)sa + num * sizeof(SOCKET_ADDRESS));
sa_list->iAddressCount = num;
for (p = table, i = 0; p; p = p->Next) for (p = table, i = 0; p; p = p->Next)
{ {
if (!p->IpAddressList.IpAddress.String[0]) continue; if (!p->IpAddressList.IpAddress.String[0]) continue;
sa[i].lpSockaddr = (SOCKADDR *)&sockaddr[i]; sa[i].lpSockaddr = (SOCKADDR *)&sockaddr[i];
sa[i].iSockaddrLength = sizeof(SOCKADDR); sa[i].iSockaddrLength = sizeof(SOCKADDR);
sockaddr[i].sin_family = AF_INET; sockaddr[i].sin_family = AF_INET;
sockaddr[i].sin_port = 0; sockaddr[i].sin_port = 0;
sockaddr[i].sin_addr.WS_s_addr = inet_addr(p->IpAddressList.IpAddress.String); sockaddr[i].sin_addr.WS_s_addr = inet_addr(p->IpAddressList.IpAddress.String);
i++; i++;
}
} }
HeapFree(GetProcessHeap(), 0, table); HeapFree(GetProcessHeap(), 0, table);
......
...@@ -7499,6 +7499,11 @@ static void test_address_list_query(void) ...@@ -7499,6 +7499,11 @@ static void test_address_list_query(void)
ok(WSAGetLastError() == WSAEFAULT, "Got unexpected error %d.\n", WSAGetLastError()); ok(WSAGetLastError() == WSAEFAULT, "Got unexpected error %d.\n", WSAGetLastError());
bytes_returned = 0xdeadbeef; bytes_returned = 0xdeadbeef;
ret = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, NULL, size, &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);
ret = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, address_list, 1, &bytes_returned, NULL, NULL); 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(ret == SOCKET_ERROR, "Got unexpected ret %d.\n", ret);
ok(WSAGetLastError() == WSAEINVAL, "Got unexpected error %d.\n", WSAGetLastError()); ok(WSAGetLastError() == WSAEINVAL, "Got unexpected error %d.\n", WSAGetLastError());
......
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