From 32724def728e54b9023fbec9d43854e8afdbf43c Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Tue, 7 Oct 2014 08:41:12 +0200 Subject: [PATCH] ws2_32: Return an error if "out_buff" is NULL for SIO_ADDRESS_LIST_QUERY. --- dlls/ws2_32/socket.c | 39 ++++++++++++++++++--------------------- dlls/ws2_32/tests/sock.c | 5 +++++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 98ed686f41b..aba7d3fbb0a 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -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) { 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; if (!table || GetAdaptersInfo(table, &size)) @@ -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(SOCKADDR) * num; - if (total > out_size) + if (total > out_size || !out_buff) { *ret_size = total; HeapFree(GetProcessHeap(), 0, table); @@ -3970,29 +3974,22 @@ INT WINAPI WSAIoctl(SOCKET s, DWORD code, LPVOID in_buff, DWORD in_size, LPVOID break; } - if (out_buff) - { - unsigned int i; - SOCKET_ADDRESS *sa; - 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; + sa_list = out_buff; + 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) - { - if (!p->IpAddressList.IpAddress.String[0]) continue; + for (p = table, i = 0; p; p = p->Next) + { + if (!p->IpAddressList.IpAddress.String[0]) continue; - sa[i].lpSockaddr = (SOCKADDR *)&sockaddr[i]; - sa[i].iSockaddrLength = sizeof(SOCKADDR); + sa[i].lpSockaddr = (SOCKADDR *)&sockaddr[i]; + sa[i].iSockaddrLength = sizeof(SOCKADDR); - sockaddr[i].sin_family = AF_INET; - sockaddr[i].sin_port = 0; - sockaddr[i].sin_addr.WS_s_addr = inet_addr(p->IpAddressList.IpAddress.String); - i++; - } + sockaddr[i].sin_family = AF_INET; + sockaddr[i].sin_port = 0; + sockaddr[i].sin_addr.WS_s_addr = inet_addr(p->IpAddressList.IpAddress.String); + i++; } HeapFree(GetProcessHeap(), 0, table); diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 1d61f9a2ed0..0ad6e8a2d41 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -7499,6 +7499,11 @@ static void test_address_list_query(void) ok(WSAGetLastError() == WSAEFAULT, "Got unexpected error %d.\n", WSAGetLastError()); 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); ok(ret == SOCKET_ERROR, "Got unexpected ret %d.\n", ret); ok(WSAGetLastError() == WSAEINVAL, "Got unexpected error %d.\n", WSAGetLastError()); -- 2.11.4.GIT