diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 55a6fa7b81b..e3898c2ca21 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -1579,8 +1579,10 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder) ret = ERROR_INVALID_PARAMETER; else { DWORD numEntries = getNumTcpEntries(); - DWORD size = sizeof(MIB_TCPTABLE) + (numEntries - 1) * sizeof(MIB_TCPROW); + DWORD size = sizeof(MIB_TCPTABLE); + if (numEntries > 1) + size += (numEntries - 1) * sizeof(MIB_TCPROW); if (!pTcpTable || *pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; @@ -1588,8 +1590,9 @@ DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder) else { ret = getTcpTable(&pTcpTable, numEntries, 0, 0); if (!ret) { - size = sizeof(MIB_TCPTABLE) + (pTcpTable->dwNumEntries - 1) * - sizeof(MIB_TCPROW); + size = sizeof(MIB_TCPTABLE); + if (numEntries > 1) + size += (numEntries - 1) * sizeof(MIB_TCPROW); *pdwSize = size; if (bOrder) diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c index 1ba57b194ed..6642804678f 100644 --- a/dlls/iphlpapi/ipstats.c +++ b/dlls/iphlpapi/ipstats.c @@ -1212,9 +1212,11 @@ DWORD getTcpTable(PMIB_TCPTABLE *ppTcpTable, DWORD maxEntries, HANDLE heap, if (!*ppTcpTable) { - *ppTcpTable = HeapAlloc (heap, flags, - sizeof (MIB_TCPTABLE) + - (numEntries - 1) * sizeof (MIB_TCPROW)); + DWORD size = sizeof(MIB_TCPTABLE); + + if (numEntries > 1) + size += (numEntries - 1) * sizeof (MIB_TCPROW); + *ppTcpTable = HeapAlloc (heap, flags, size); if (!*ppTcpTable) { ERR ("Out of memory!\n");