VirtualBox

Changeset 51803 in vbox


Ignore:
Timestamp:
Jul 2, 2014 9:28:15 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94645
Message:

Use CreateFileW instead of CreateFileA when verifying the install files and plugins.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPR3HardenedVerify.cpp

    r51772 r51803  
    478478        {
    479479#if defined(RT_OS_WINDOWS) /** @todo Need to use WCHAR on windows! */
    480             HANDLE hFile = CreateFile(szPath,
    481                                       GENERIC_READ,
    482                                       FILE_SHARE_READ,
    483                                       NULL,
    484                                       OPEN_EXISTING,
    485                                       FILE_ATTRIBUTE_NORMAL,
    486                                       NULL);
    487             if (hFile != INVALID_HANDLE_VALUE)
     480            PRTUTF16 pwszPath;
     481            rc = RTStrToUtf16(szPath, &pwszPath);
     482            if (RT_SUCCESS(rc))
    488483            {
     484                HANDLE hFile = CreateFileW(pwszPath,
     485                                           GENERIC_READ,
     486                                           FILE_SHARE_READ,
     487                                           NULL,
     488                                           OPEN_EXISTING,
     489                                           FILE_ATTRIBUTE_NORMAL,
     490                                           NULL);
     491                if (hFile != INVALID_HANDLE_VALUE)
     492                {
    489493# if defined(VBOX_WITH_HARDENING) && !defined(IN_SUP_R3_STATIC) /* Latter: Not in VBoxCpuReport and friends. */
    490494
    491                 char szErr[1024];
    492                 RTERRINFO ErrInfo;
    493                 RTErrInfoInit(&ErrInfo, szErr, sizeof(szErr));
    494 
    495                 uint32_t fFlags = SUPHNTVI_F_REQUIRE_BUILD_CERT;
    496                 if (pFile->enmType == kSupIFT_Rc)
    497                     fFlags |= SUPHNTVI_F_RC_IMAGE;
    498 
    499                 rc = supHardenedWinVerifyImageByHandleNoName(hFile, fFlags, &ErrInfo);
    500                 if (RT_FAILURE(rc))
    501                 {
    502                     rc = supR3HardenedError(rc, fFatal, "supR3HardenedVerifyFileInternal: '%s': Image verify error rc=%Rrc: %s\n",
    503                                             szPath, rc, szErr);
    504                     CloseHandle(hFile);
     495                    char szErr[1024];
     496                    RTERRINFO ErrInfo;
     497                    RTErrInfoInit(&ErrInfo, szErr, sizeof(szErr));
     498
     499                    uint32_t fFlags = SUPHNTVI_F_REQUIRE_BUILD_CERT;
     500                    if (pFile->enmType == kSupIFT_Rc)
     501                        fFlags |= SUPHNTVI_F_RC_IMAGE;
     502
     503                    rc = supHardenedWinVerifyImageByHandleNoName(hFile, fFlags, &ErrInfo);
     504                    if (RT_FAILURE(rc))
     505                    {
     506                        rc = supR3HardenedError(rc, fFatal, "supR3HardenedVerifyFileInternal: '%s': Image verify error rc=%Rrc: %s\n",
     507                                                szPath, rc, szErr);
     508                        CloseHandle(hFile);
     509                    }
     510                    else
     511# endif
     512                    {
     513                        /* it's valid. */
     514                        if (fLeaveFileOpen)
     515                            pVerified->hFile = (intptr_t)hFile;
     516                        else
     517                            CloseHandle(hFile);
     518                        pVerified->fValidated = true;
     519                    }
    505520                }
    506521                else
    507 #endif
    508522                {
    509                     /* it's valid. */
    510                     if (fLeaveFileOpen)
    511                         pVerified->hFile = (intptr_t)hFile;
    512                     else
    513                         CloseHandle(hFile);
    514                     pVerified->fValidated = true;
     523                    int err = GetLastError();
     524                    if (!pFile->fOptional || err != ERROR_FILE_NOT_FOUND)
     525                        rc = supR3HardenedError(VERR_PATH_NOT_FOUND, fFatal,
     526                                                "supR3HardenedVerifyFileInternal: Failed to open '%s': err=%d\n", szPath, err);
    515527                }
     528                RTUtf16Free(pwszPath);
    516529            }
    517530            else
    518             {
    519                 int err = GetLastError();
    520                 if (!pFile->fOptional || err != ERROR_FILE_NOT_FOUND)
    521                     rc = supR3HardenedError(VERR_PATH_NOT_FOUND, fFatal,
    522                                             "supR3HardenedVerifyFileInternal: Failed to open '%s': err=%d\n", szPath, err);
    523             }
     531                rc = supR3HardenedError(rc, fFatal, "supR3HardenedVerifyFileInternal: Failed to convert '%s' to UTF-16: %Rrc\n",
     532                                        szPath, rc);
    524533#else /* UNIXY */
    525534            int fd = open(szPath, O_RDONLY, 0);
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