VirtualBox

Ignore:
Timestamp:
Oct 17, 2016 10:38:53 AM (8 years ago)
Author:
vboxsync
Message:

VBoxTray,InstallerHelper,VBoxService: Use RTLOCALIPC_FLAGS_NATIVE_NAME and format the pipe name into buffers of the exact same size.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/Installer/InstallHelper/VBoxGuestInstallHelper.cpp

    r64291 r64292  
    3333#include <iprt/localipc.h>
    3434#include <iprt/mem.h>
     35#include <iprt/process.h>
    3536#include <iprt/string.h>
    3637
     
    138139static int vboxConnectToVBoxTray(RTLOCALIPCSESSION *phSession)
    139140{
    140     int rc = VINF_SUCCESS;
    141 
    142     RTUTF16 wszUserName[255];
    143     DWORD cchUserName = sizeof(wszUserName) / sizeof(RTUTF16);
    144     BOOL fRc = GetUserNameW(wszUserName, &cchUserName);
    145     if (!fRc)
    146         rc = RTErrConvertFromWin32(GetLastError());
    147 
     141    char szPipeName[512 + sizeof(VBOXTRAY_IPC_PIPE_PREFIX)];
     142    memcpy(szPipeName, VBOXTRAY_IPC_PIPE_PREFIX, sizeof(VBOXTRAY_IPC_PIPE_PREFIX));
     143    int rc = RTProcQueryUsername(NIL_RTPROCESS,
     144                                 &szPipeName[sizeof(VBOXTRAY_IPC_PIPE_PREFIX) - 1],
     145                                 sizeof(szPipeName) - sizeof(VBOXTRAY_IPC_PIPE_PREFIX) + 1,
     146                                 NULL /*pcbUser*/);
    148147    if (RT_SUCCESS(rc))
    149     {
    150         char *pszUserName;
    151         rc = RTUtf16ToUtf8(wszUserName, &pszUserName);
    152         if (RT_SUCCESS(rc))
    153         {
    154             char szPipeName[255];
    155             if (RTStrPrintf(szPipeName, sizeof(szPipeName), "%s%s",
    156                             VBOXTRAY_IPC_PIPE_PREFIX, pszUserName))
    157             {
    158                 rc = RTLocalIpcSessionConnect(phSession, szPipeName, 0 /* Flags */);
    159             }
    160             else
    161                 rc = VERR_NO_MEMORY;
    162 
    163             RTStrFree(pszUserName);
    164         }
    165     }
    166 
     148        rc = RTLocalIpcSessionConnect(phSession, szPipeName, RTLOCALIPC_FLAGS_NATIVE_NAME);
    167149    return rc;
    168150}
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