Author: spetreolle
Date: Mon Mar 30 18:10:36 2015
New Revision: 66981
URL:
http://svn.reactos.org/svn/reactos?rev=66981&view=rev
Log:
[IPHLPAPI]
Make GetAdaptersAddresses work, with parameters check.
More work is needed :
-it returns the loopback, which shouldn't appear with default flags.
-the required size is fixed.
Modified:
trunk/reactos/dll/win32/iphlpapi/address.c
Modified: trunk/reactos/dll/win32/iphlpapi/address.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/address…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/address.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/address.c [iso-8859-1] Mon Mar 30 18:10:36 2015
@@ -9,7 +9,7 @@
#include "iphlpapi_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
-
+#if 1
/* Helper for GetAdaptersAddresses:
* Retrieves the list of network adapters from tcpip.sys */
static
@@ -283,12 +283,22 @@
ULONG i;
ULONG TotalSize = 0, RemainingSize;
BYTE* Ptr = (BYTE*)pAdapterAddresses;
+ DWORD MIN_SIZE = 15 * 1024;
+ PIP_ADAPTER_ADDRESSES PreviousAA = NULL;
FIXME("GetAdaptersAddresses - Semi Stub: Family %u, Flags 0x%08x, Reserved %p,
pAdapterAddress %p, pOutBufLen %p.\n",
Family, Flags, Reserved, pAdapterAddresses, pOutBufLen);
if (!pOutBufLen)
return ERROR_INVALID_PARAMETER;
+
+ // FIXME: the exact needed size should be computed first, BEFORE doing any write to
the output buffer.
+ // As suggested by MSDN, require a 15 KB buffer, which allows to React properly to
length checks.
+ if(!Ptr || *pOutBufLen < MIN_SIZE)
+ {
+ *pOutBufLen = MIN_SIZE;
+ return ERROR_BUFFER_OVERFLOW;
+ }
switch(Family)
{
@@ -334,7 +344,7 @@
/* Let's see if we got any adapter. */
for (i = 0; i < InterfacesCount; i++)
{
- PIP_ADAPTER_ADDRESSES CurrentAA = (PIP_ADAPTER_ADDRESSES)Ptr, PreviousAA = NULL;
+ PIP_ADAPTER_ADDRESSES CurrentAA = (PIP_ADAPTER_ADDRESSES)Ptr;
ULONG CurrentAASize = 0;
if (InterfacesList[i].tei_entity == IF_ENTITY)
@@ -345,6 +355,10 @@
/* Remember we got one */
AdaptersCount++;
+
+ /* Set the pointer to this instance in the previous one*/
+ if(PreviousAA)
+ PreviousAA->Next = CurrentAA;
/* Of course we need some space for the base structure. */
CurrentAASize = sizeof(IP_ADAPTER_ADDRESSES);
@@ -409,7 +423,6 @@
CurrentAA->Mtu = Entry->if_mtu;
CurrentAA->IfType = Entry->if_type;
CurrentAA->OperStatus = Entry->if_operstatus;
- CurrentAA->Next = PreviousAA;
/* Next items */
Ptr = (BYTE*)(CurrentAA + 1);
@@ -628,6 +641,7 @@
HeapFree(GetProcessHeap(), 0, InterfacesList);
NtClose(TcpFile);
*pOutBufLen = TotalSize;
+ TRACE("TotalSize: %x\n", *pOutBufLen);
return ERROR_SUCCESS;
Error:
@@ -637,3 +651,4 @@
NtClose(TcpFile);
return RtlNtStatusToDosError(Status);
}
+#endif