VirtualBox

Ignore:
Timestamp:
Sep 28, 2015 2:16:53 AM (9 years ago)
Author:
vboxsync
Message:

vboxserviceVMInfoWriteNetwork: Workaround for bug in GetTcpipInterfaceList on NT4 SP1 (and possible earlier / later).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp

    r57358 r57920  
    962962    }
    963963
    964     INTERFACE_INFO InterfaceList[20] = {0};
    965     unsigned long nBytesReturned = 0;
    966     if (WSAIoctl(sd,
    967                  SIO_GET_INTERFACE_LIST,
    968                  0,
    969                  0,
    970                  &InterfaceList,
    971                  sizeof(InterfaceList),
    972                  &nBytesReturned,
    973                  0,
    974                  0) ==  SOCKET_ERROR)
     964    INTERFACE_INFO aInterfaces[20] = {0};
     965    DWORD cbReturned = 0;
     966# ifdef TARGET_NT4
     967    /* Workaround for uninitialized variable used in memcpy in GetTcpipInterfaceList
     968       (NT4SP1 at least).  It seems to be happy enough with garbages, no failure
     969       returns so far, so we just need to prevent it from crashing by filling the
     970       stack with valid pointer values prior to the API call. */
     971    _asm
     972    {
     973        mov     edx, edi
     974        lea     eax, aInterfaces
     975        mov     [esp - 0x1000], eax
     976        mov     [esp - 0x2000], eax
     977        mov     ecx, 0x2000/4 - 1
     978        cld
     979        lea     edi, [esp - 0x2000]
     980        rep stosd
     981        mov     edi, edx
     982    }
     983# endif
     984    if (   WSAIoctl(sd,
     985                    SIO_GET_INTERFACE_LIST,
     986                    NULL,                /* pvInBuffer */
     987                    0,                   /* cbInBuffer */
     988                    &aInterfaces[0],     /* pvOutBuffer */
     989                    sizeof(aInterfaces), /* cbOutBuffer */
     990                    &cbReturned,
     991                    NULL,                /* pOverlapped */
     992                    NULL)                /* pCompletionRoutine */
     993        == SOCKET_ERROR)
    975994    {
    976995        VBoxServiceError("VMInfo/Network: Failed to WSAIoctl() on socket: Error: %d\n", WSAGetLastError());
     
    979998        return RTErrConvertFromWin32(WSAGetLastError());
    980999    }
    981     int cIfacesSystem = nBytesReturned / sizeof(INTERFACE_INFO);
     1000    int cIfacesSystem = cbReturned / sizeof(INTERFACE_INFO);
    9821001
    9831002    /** @todo Use GetAdaptersInfo() and GetAdapterAddresses (IPv4 + IPv6) for more information. */
     
    9861005        sockaddr_in *pAddress;
    9871006        u_long nFlags = 0;
    988         if (InterfaceList[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */
     1007        if (aInterfaces[i].iiFlags & IFF_LOOPBACK) /* Skip loopback device. */
    9891008            continue;
    990         nFlags = InterfaceList[i].iiFlags;
    991         pAddress = (sockaddr_in *)&(InterfaceList[i].iiAddress);
     1009        nFlags = aInterfaces[i].iiFlags;
     1010        pAddress = (sockaddr_in *)&(aInterfaces[i].iiAddress);
    9921011        Assert(pAddress);
    9931012        char szIp[32];
     
    9961015        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp);
    9971016
    998         pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress);
     1017        pAddress = (sockaddr_in *) & (aInterfaces[i].iiBroadcastAddress);
    9991018        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfsReported);
    10001019        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
    10011020
    1002         pAddress = (sockaddr_in *)&(InterfaceList[i].iiNetmask);
     1021        pAddress = (sockaddr_in *)&(aInterfaces[i].iiNetmask);
    10031022        RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfsReported);
    10041023        VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr));
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette