Commit 7e584b43 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

iphlpapi: Don't allocate gobs of memory if the UDP table is empty.

parent 72a59de2
......@@ -1665,8 +1665,10 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numEntries = getNumUdpEntries();
DWORD size = sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW);
DWORD size = sizeof(MIB_UDPTABLE);
if (numEntries > 1)
size += (numEntries - 1) * sizeof(MIB_UDPROW);
if (!pUdpTable || *pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
......@@ -1676,8 +1678,9 @@ DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder)
ret = getUdpTable(&table, GetProcessHeap(), 0);
if (!ret) {
size = sizeof(MIB_UDPTABLE) + (table->dwNumEntries - 1) *
sizeof(MIB_UDPROW);
size = sizeof(MIB_UDPTABLE);
if (table->dwNumEntries > 1)
size += (table->dwNumEntries - 1) * sizeof(MIB_UDPROW);
if (*pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
......
......@@ -1112,9 +1112,12 @@ DWORD getUdpTable(PMIB_UDPTABLE *ppUdpTable, HANDLE heap, DWORD flags)
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numEntries = getNumUdpEntries();
PMIB_UDPTABLE table = HeapAlloc(heap, flags,
sizeof(MIB_UDPTABLE) + (numEntries - 1) * sizeof(MIB_UDPROW));
DWORD size = sizeof(MIB_UDPTABLE);
PMIB_UDPTABLE table;
if (numEntries > 1)
size += (numEntries - 1) * sizeof(MIB_UDPROW);
table = HeapAlloc(heap, flags, size);
if (table) {
FILE *fp;
......
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