Author: tfaber
Date: Tue May 10 17:53:36 2016
New Revision: 71308
URL:
http://svn.reactos.org/svn/reactos?rev=71308&view=rev
Log:
[IPHLPAPI]
- Don't use uninitialized values in AllocateAndGet*TableFromStack functions. CID
716757
- Free buffers on failure
CORE-11227 #resolve
Modified:
trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] Tue May 10 17:53:36
2016
@@ -117,10 +117,15 @@
else {
DWORD dwSize = 0;
+ *ppIfTable = NULL;
ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
if (ret == ERROR_INSUFFICIENT_BUFFER) {
*ppIfTable = (PMIB_IFTABLE)HeapAlloc(heap, flags, dwSize);
ret = GetIfTable(*ppIfTable, &dwSize, bOrder);
+ if (ret != NO_ERROR) {
+ HeapFree(heap, flags, *ppIfTable);
+ *ppIfTable = NULL;
+ }
}
}
TRACE("returning %ld\n", ret);
@@ -156,10 +161,15 @@
else {
DWORD dwSize = 0;
+ *ppIpAddrTable = NULL;
ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
if (ret == ERROR_INSUFFICIENT_BUFFER) {
*ppIpAddrTable = (PMIB_IPADDRTABLE)HeapAlloc(heap, flags, dwSize);
ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder);
+ if (ret != NO_ERROR) {
+ HeapFree(heap, flags, *ppIpAddrTable);
+ *ppIpAddrTable = NULL;
+ }
}
}
TRACE("returning %ld\n", ret);
@@ -193,10 +203,15 @@
else {
DWORD dwSize = 0;
+ *ppIpForwardTable = NULL;
ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
if (ret == ERROR_INSUFFICIENT_BUFFER) {
*ppIpForwardTable = (PMIB_IPFORWARDTABLE)HeapAlloc(heap, flags, dwSize);
ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder);
+ if (ret != NO_ERROR) {
+ HeapFree(heap, flags, *ppIpForwardTable);
+ *ppIpForwardTable = NULL;
+ }
}
}
TRACE("returning %ld\n", ret);
@@ -232,10 +247,15 @@
else {
DWORD dwSize = 0;
+ *ppIpNetTable = NULL;
ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
if (ret == ERROR_INSUFFICIENT_BUFFER) {
*ppIpNetTable = (PMIB_IPNETTABLE)HeapAlloc(heap, flags, dwSize);
ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder);
+ if (ret != NO_ERROR) {
+ HeapFree(heap, flags, *ppIpNetTable);
+ *ppIpNetTable = NULL;
+ }
}
}
TRACE("returning %ld\n", ret);
@@ -271,10 +291,15 @@
else {
DWORD dwSize = 0;
+ *ppTcpTable = NULL;
ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
if (ret == ERROR_INSUFFICIENT_BUFFER) {
*ppTcpTable = (PMIB_TCPTABLE)HeapAlloc(heap, flags, dwSize);
ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder);
+ if (ret != NO_ERROR) {
+ HeapFree(heap, flags, *ppTcpTable);
+ *ppTcpTable = NULL;
+ }
}
}
TRACE("returning %ld\n", ret);
@@ -310,10 +335,15 @@
else {
DWORD dwSize = 0;
+ *ppUdpTable = NULL;
ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
if (ret == ERROR_INSUFFICIENT_BUFFER) {
*ppUdpTable = (PMIB_UDPTABLE)HeapAlloc(heap, flags, dwSize);
ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder);
+ if (ret != NO_ERROR) {
+ HeapFree(heap, flags, *ppUdpTable);
+ *ppUdpTable = NULL;
+ }
}
}
TRACE("returning %ld\n", ret);