Commit 72a59de2 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

iphlpapi: Don't allocate gobs of memory when the ARP table is empty.

parent 848e8de5
......@@ -1289,9 +1289,10 @@ DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOr
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numEntries = getNumArpEntries();
ULONG size = sizeof(MIB_IPNETTABLE) + (numEntries - 1) *
sizeof(MIB_IPNETROW);
ULONG size = sizeof(MIB_IPNETTABLE);
if (numEntries > 1)
size += (numEntries - 1) * sizeof(MIB_IPNETROW);
if (!pIpNetTable || *pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
......@@ -1301,8 +1302,9 @@ DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOr
ret = getArpTable(&table, GetProcessHeap(), 0);
if (!ret) {
size = sizeof(MIB_IPNETTABLE) + (table->dwNumEntries - 1) *
sizeof(MIB_IPNETROW);
size = sizeof(MIB_IPNETTABLE);
if (table->dwNumEntries > 1)
size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW);
if (*pdwSize < size) {
*pdwSize = size;
ret = ERROR_INSUFFICIENT_BUFFER;
......
......@@ -1009,9 +1009,12 @@ DWORD getArpTable(PMIB_IPNETTABLE *ppIpNetTable, HANDLE heap, DWORD flags)
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numEntries = getNumArpEntries();
PMIB_IPNETTABLE table = HeapAlloc(heap, flags,
sizeof(MIB_IPNETTABLE) + (numEntries - 1) * sizeof(MIB_IPNETROW));
DWORD size = sizeof(MIB_IPNETTABLE);
PMIB_IPNETTABLE table;
if (numEntries > 1)
size += (numEntries - 1) * sizeof(MIB_IPNETROW);
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