VirtualBox

Ignore:
Timestamp:
Jun 26, 2013 2:24:02 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
86742
Message:

crOpenGL: fail if GetModuleFileName or GetSystemDirectory fail, and switch to unicode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/util/dll.c

    r46660 r46805  
    167167        char *dll_err;
    168168#if defined(WINDOWS)
    169     char   szPath[MAX_PATH];
     169    WCHAR   szwPath[MAX_PATH];
     170    UINT   cwcPath = 0;
    170171
    171172    (void) resolveGlobal;
     
    174175    if (PathIsRelative(dllname))
    175176    {
    176         size_t cbName  = strlen(dllname) + 1;
     177        size_t cName  = strlen(dllname) + 1;
    177178#  ifdef IN_GUEST
    178         UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
     179        cwcPath = GetSystemDirectoryW(szwPath, RT_ELEMENTS(szwPath));
     180        if (!cwcPath || cwcPath >= MAX_PATH)
     181        {
     182            DWORD winEr = GetLastError();
     183            crError("GetSystemDirectoryW failed err %d", winEr);
     184            SetLastError(winEr);
     185            return NULL;
     186        }
    179187#  else
    180         UINT   cchPath = GetModuleFileNameA(NULL, szPath, sizeof(szPath));
    181         if (cchPath != 0 && cchPath <= sizeof(szPath))
     188        WCHAR * pszwSlashFile;
     189        cwcPath = GetModuleFileNameW(NULL, szwPath, RT_ELEMENTS(szwPath));
     190        if (!cwcPath || cwcPath >= MAX_PATH)
    182191        {
    183             char * pszSlashFile = strrchr(szPath, '\\');
    184             if (pszSlashFile)
    185             {
    186                 cchPath = pszSlashFile - szPath;
    187             }
     192            DWORD winEr = GetLastError();
     193            crError("GetModuleFileNameW failed err %d", winEr);
     194            SetLastError(winEr);
     195            return NULL;
    188196        }
     197
     198        pszwSlashFile = wcsrchr(szwPath, L'\\');
     199        if (!pszwSlashFile)
     200        {
     201            crError("failed to match file name");
     202            SetLastError(ERROR_PATH_NOT_FOUND);
     203            return NULL;
     204        }
     205
     206        cwcPath = pszwSlashFile - szwPath;
    189207#  endif
    190208
    191         if (cchPath + 1 + cbName > sizeof(szPath))
     209        if (cwcPath + 1 + cName > MAX_PATH)
    192210        {
    193211            crError("invalid path specified");
     
    195213            return NULL;
    196214        }
    197         szPath[cchPath] = '\\';
    198         memcpy(&szPath[cchPath + 1], dllname, cbName);
    199 
    200         dllname = szPath;
     215        szwPath[cwcPath] = '\\';
     216        ++cwcPath;
     217    }
     218
     219    if (!MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, dllname, -1, &szwPath[cwcPath], MAX_PATH - cwcPath))
     220    {
     221        DWORD winEr = GetLastError();
     222        crError("MultiByteToWideChar failed err %d", winEr);
     223        SetLastError(winEr);
     224        return NULL;
    201225    }
    202226# endif // CR_NO_GL_SYSTEM_PATH
     
    207231
    208232#if defined(WINDOWS)
    209     dll->hinstLib = LoadLibrary( dllname );
     233    dll->hinstLib = LoadLibraryW( szwPath );
    210234    if (!dll->hinstLib)
    211235    {
Note: See TracChangeset for help on using the changeset viewer.

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