Commit 848e8de5 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

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

parent 5349c5e8
......@@ -1222,9 +1222,10 @@ DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSi
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numRoutes = getNumRoutes();
ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) *
sizeof(MIB_IPFORWARDROW);
ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
if (numRoutes > 1)
sizeNeeded += (numRoutes - 1) * sizeof(MIB_IPFORWARDROW);
if (!pIpForwardTable || *pdwSize < sizeNeeded) {
*pdwSize = sizeNeeded;
ret = ERROR_INSUFFICIENT_BUFFER;
......@@ -1234,8 +1235,9 @@ DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSi
ret = getRouteTable(&table, GetProcessHeap(), 0);
if (!ret) {
sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->dwNumEntries - 1) *
sizeof(MIB_IPFORWARDROW);
sizeNeeded = sizeof(MIB_IPFORWARDTABLE);
if (table->dwNumEntries > 1)
sizeNeeded += (table->dwNumEntries - 1) * sizeof(MIB_IPFORWARDROW);
if (*pdwSize < sizeNeeded) {
*pdwSize = sizeNeeded;
ret = ERROR_INSUFFICIENT_BUFFER;
......
......@@ -777,9 +777,12 @@ DWORD getRouteTable(PMIB_IPFORWARDTABLE *ppIpForwardTable, HANDLE heap,
ret = ERROR_INVALID_PARAMETER;
else {
DWORD numRoutes = getNumRoutes();
PMIB_IPFORWARDTABLE table = HeapAlloc(heap, flags,
sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) * sizeof(MIB_IPFORWARDROW));
DWORD size = sizeof(MIB_IPFORWARDTABLE);
PMIB_IPFORWARDTABLE table;
if (numRoutes > 1)
size += (numRoutes - 1) * sizeof(MIB_IPFORWARDROW);
table = HeapAlloc(heap, flags, size);
if (table) {
#if defined(HAVE_SYS_SYSCTL_H) && defined(NET_RT_DUMP)
int mib[6] = {CTL_NET, PF_ROUTE, 0, PF_INET, NET_RT_DUMP, 0};
......
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