diff --git a/dlls/iphlpapi/iphlpapi_main.c b/dlls/iphlpapi/iphlpapi_main.c index 92df63124d2..db14d74128f 100644 --- a/dlls/iphlpapi/iphlpapi_main.c +++ b/dlls/iphlpapi/iphlpapi_main.c @@ -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; diff --git a/dlls/iphlpapi/ipstats.c b/dlls/iphlpapi/ipstats.c index 3605d647235..a7fd40d7bf0 100644 --- a/dlls/iphlpapi/ipstats.c +++ b/dlls/iphlpapi/ipstats.c @@ -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;