VirtualBox

Changeset 107901 in vbox


Ignore:
Timestamp:
Jan 22, 2025 10:21:48 PM (2 weeks ago)
Author:
vboxsync
Message:

Windows driver installation: Fixed incorrect size passed to SetupDiGetINFClassW in VBoxWinDrvInfOpen and RTUtf16Copy+RTUtf16Cat in VBoxWinDrvInfQueryModelEx; tried to fix bogus key+value parsing in VBoxWinDrvInfQuerySectionVerEx. bugref:10762

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/VBoxWinDrvDefs.h

    r107076 r107901  
    11/* $Id$ */
    22/** @file
    3  * VBoxWinDrvDefs - Common definitions for Windows driver functions.
     3 * VBoxWinDrvDefs - Common definitions for Windows driver installation functions.
    44 */
    55
     
    8585 * Structure for keeping INF Version section information.
    8686 */
    87 typedef struct _VBOXWINDRVINFSEC_VERSION
     87typedef struct VBOXWINDRVINFSECVERSION
    8888{
    8989    /** Catalog (.cat) file. */
     
    9393    /** Provider name. */
    9494    RTUTF16 wszProvider[VBOXWINDRVINF_MAX_PROVIDER_NAME_LEN];
    95 } VBOXWINDRVINFSEC_VERSION;
     95} VBOXWINDRVINFSECVERSION;
    9696/** Pointer to structure for keeping INF Version section information. */
    97 typedef VBOXWINDRVINFSEC_VERSION *PVBOXWINDRVINFSEC_VERSION;
     97typedef VBOXWINDRVINFSECVERSION *PVBOXWINDRVINFSECVERSION;
    9898
    9999#endif /* !VBOX_INCLUDED_GuestHost_VBoxWinDrvDefs_h */
  • trunk/include/VBox/GuestHost/VBoxWinDrvStore.h

    r106395 r107901  
    5757 * Structure for keeping a generic Windows driver store list.
    5858 */
    59 typedef struct _VBOXWINDRVSTORELIST
     59typedef struct VBOXWINDRVSTORELIST
    6060{
    6161    /** List node. */
     
    7070 * Structure for keeping a Windows driver store entry.
    7171 */
    72 typedef struct _VBOXWINDRVSTOREENTRY
     72typedef struct VBOXWINDRVSTOREENTRY
    7373{
    7474    RTLISTNODE Node;
    7575    /** Version section information. */
    76     VBOXWINDRVINFSEC_VERSION Ver;
     76    VBOXWINDRVINFSECVERSION Ver;
    7777    /** Full path to the oemXXX.inf file within the driver store. */
    7878    RTUTF16                  wszInfFile[RTPATH_MAX];
     
    9090typedef VBOXWINDRVSTOREENTRY *PVBOXWINDRVSTOREENTRY;
    9191
    92 struct _VBOXWINDRVSTORE;
     92struct VBOXWINDRVSTORE;
    9393/** Pointer to Windows driver store instance data. */
    94 typedef struct _VBOXWINDRVSTORE *PVBOXWINDRVSTORE;
     94typedef struct VBOXWINDRVSTORE *PVBOXWINDRVSTORE;
    9595
    9696/**
    9797 * Interface for a Windows driver store implementation.
    9898 */
    99 typedef struct _VBOXWINDRVSTOREIFACE
     99typedef struct VBOXWINDRVSTOREIFACE
    100100{
    101101    /**
     
    133133 * Enumeration for a driver store backend.
    134134 */
    135 typedef enum _VBOXWINDRVSTOREBACKENDTYPE
     135typedef enum VBOXWINDRVSTOREBACKENDTYPE
    136136{
    137137    /** Invalid. */
     
    146146 * Currently only the (local) file system backend is supported.
    147147 */
    148 typedef struct _VBOXWINDRVSTOREBACKEND
     148typedef struct VBOXWINDRVSTOREBACKEND
    149149{
    150150    VBOXWINDRVSTOREBACKENDTYPE enmType;
     
    165165 * Structure for keeping Windows driver store instance data.
    166166 */
    167 typedef struct _VBOXWINDRVSTORE
     167typedef struct VBOXWINDRVSTORE
    168168{
    169169    /** The current list of drivers. */
  • trunk/src/VBox/GuestHost/installation/VBoxWinDrvCommon.cpp

    r107395 r107901  
    11/* $Id$ */
    22/** @file
    3  * VBoxWinDrvCommon - Common Windows driver functions.
     3 * VBoxWinDrvCommon - Common Windows driver installation functions.
    44 */
    55
     
    5252
    5353/*********************************************************************************************************************************
    54 *   Defines                                                                                                                      *
    55 *********************************************************************************************************************************/
    56 
    57 
    58 /*********************************************************************************************************************************
    59 *   Defined Constants And Macros                                                                                                 *
    60 *********************************************************************************************************************************/
    61 
    62 
    63 /*********************************************************************************************************************************
    6454*   Prototypes                                                                                                                   *
    6555*********************************************************************************************************************************/
     
    7767VBOXWINDRVINFTYPE VBoxWinDrvInfGetTypeEx(HINF hInf, PRTUTF16 *ppwszSection)
    7868{
     69    if (ppwszSection)
     70        *ppwszSection = NULL;
     71
    7972    /*
    8073     * Regular driver?
     
    133126    if (   pwszManufacturerSection
    134127        && pwszPrimitiveSection)
    135     {
    136128        return VBOXWINDRVINFTYPE_INVALID;
    137     }
    138     else if (pwszManufacturerSection)
     129    if (pwszManufacturerSection)
    139130    {
    140131        if (ppwszSection)
    141132            *ppwszSection = RTUtf16Dup(pwszManufacturerSection);
    142 
    143133        return VBOXWINDRVINFTYPE_NORMAL;
    144134    }
    145     else if (pwszPrimitiveSection)
     135    if (pwszPrimitiveSection)
    146136    {
    147137        if (ppwszSection)
    148138            *ppwszSection = RTUtf16Dup(pwszPrimitiveSection);
    149 
    150139        return VBOXWINDRVINFTYPE_PRIMITIVE;
    151140    }
     
    189178 * @param   iValue              Index to query.
    190179 * @param   ppwszValue          Where to return the value on success.
    191  * @param   pcwcValue           Where to return the number of characters for \a ppwszValue. Optional an can be NULL.
     180 * @param   pcwcValue           Where to return the number of characters in the
     181 *                              string returned via \a ppwszValue, including the
     182 *                              zero terminator. Optional and can be NULL.
    192183 */
    193184int VBoxWinDrvInfQueryKeyValue(PINFCONTEXT pCtx, DWORD iValue, PRTUTF16 *ppwszValue, PDWORD pcwcValue)
     
    231222 *                              Currently only the first model (index 0) is supported.
    232223 * @param   ppwszValue          Where to return the model name on success.
    233  * @param   pcwcValue           Where to return the number of characters for \a ppwszValue. Optional an can be NULL.
     224 * @param   pcwcValue           Where to return the number of characters in the
     225 *                              string returned via \a ppwszValue, including the
     226 *                              zero terminator. Optional and can be NULL.
    234227 */
    235228int VBoxWinDrvInfQueryModelEx(HINF hInf, PCRTUTF16 pwszSection, unsigned uIndex, PRTUTF16 *ppwszValue, PDWORD pcwcValue)
    236229{
    237     AssertPtrReturn(pwszSection, VERR_INVALID_POINTER);
    238     AssertReturn(uIndex == 0, VERR_INVALID_PARAMETER);
    239 
    240230    *ppwszValue = NULL;
    241231    if (pcwcValue)
    242232        *pcwcValue = 0;
    243 
    244     int rc = VINF_SUCCESS;
     233    AssertPtrReturn(pwszSection, VERR_INVALID_POINTER);
     234    AssertReturn(uIndex == 0, VERR_INVALID_PARAMETER);
    245235
    246236    INFCONTEXT InfCtx;
    247     rc = vboxWinDrvInfQueryContext(hInf, pwszSection, NULL, &InfCtx);
     237    int rc = vboxWinDrvInfQueryContext(hInf, pwszSection, NULL, &InfCtx);
    248238    if (RT_FAILURE(rc))
    249239        return rc;
     
    255245        return rc;
    256246
    257     PRTUTF16 pwszResult = NULL;
    258     DWORD    cwcResult  = 0;
    259 
    260247    PRTUTF16 pwszPlatform = NULL;
    261248    DWORD    cwcPlatform;
     
    270257        {
    271258            RTUTF16 wszSection[VBOXWINDRVINF_MAX_SECTION_NAME_LEN];
    272             rc = RTUtf16Copy(wszSection, sizeof(wszSection), pwszModel);
     259            rc = RTUtf16Copy(wszSection, RT_ELEMENTS(wszSection), pwszModel);
    273260            if (RT_SUCCESS(rc))
    274261            {
    275                 rc = RTUtf16Cat(wszSection, sizeof(wszSection), VBOXWINDRVINF_DECORATION_SEP_UTF16_STR);
     262                rc = RTUtf16Cat(wszSection, RT_ELEMENTS(wszSection), VBOXWINDRVINF_DECORATION_SEP_UTF16_STR);
    276263                if (RT_SUCCESS(rc))
    277264                {
    278                     rc = RTUtf16Cat(wszSection, sizeof(wszSection), pwszPlatform);
     265                    rc = RTUtf16Cat(wszSection, RT_ELEMENTS(wszSection), pwszPlatform);
    279266                    if (RT_SUCCESS(rc))
    280267                    {
    281                         pwszResult = RTUtf16Dup(wszSection);
     268                        /** @todo r=bird: Mixing RTMemAlloc and RTUtf16Dup/RTUtf16Alloc is not
     269                         *        allowed because of RTMEM_WRAP_TO_EF_APIS and other reasons!  */
     270                        PRTUTF16 pwszResult = RTUtf16Dup(wszSection);
    282271                        if (pwszResult)
    283272                        {
    284                             cwcResult = (DWORD)RTUtf16Len(wszSection);
     273                            *ppwszValue = pwszResult;
     274                            if (pcwcValue)
     275                                *pcwcValue = (DWORD)(RTUtf16Len(wszSection) + 1);
    285276                        }
    286277                        else
     
    292283        else
    293284            rc = VERR_PLATFORM_ARCH_NOT_SUPPORTED;
    294     }
    295     else /* Model w/o platform. */
    296     {
    297         pwszResult = pwszModel;
    298         cwcResult  = cwcModels;
    299         pwszModel  = NULL;
    300 
     285        RTMemFree(pwszPlatform);
     286        RTMemFree(pwszModel);
     287    }
     288    else
     289    {
     290        /* Model without platform - just return the pwszModel string. */
     291        *ppwszValue = pwszModel;
     292        if (pcwcValue)
     293            *pcwcValue = cwcModels;
    301294        rc = VINF_SUCCESS;
    302     }
    303 
    304     RTMemFree(pwszModel);
    305     RTMemFree(pwszPlatform);
    306 
    307     if (RT_SUCCESS(rc))
    308     {
    309         *ppwszValue = pwszResult;
    310         if (pcwcValue)
    311             *pcwcValue = cwcResult;
    312295    }
    313296
     
    338321 * @param   pVer                Where to return the Version section information on success.
    339322 */
    340 int VBoxWinDrvInfQuerySectionVerEx(HINF hInf, UINT uIndex, PVBOXWINDRVINFSEC_VERSION pVer)
     323int VBoxWinDrvInfQuerySectionVerEx(HINF hInf, UINT uIndex, PVBOXWINDRVINFSECVERSION pVer)
    341324{
    342325    DWORD dwSize = 0;
     
    345328        return VERR_NOT_FOUND;
    346329
    347     int rc = VINF_SUCCESS;
    348 
    349     PSP_INF_INFORMATION pInfo = (PSP_INF_INFORMATION)RTMemAlloc(dwSize);
     330    int rc;
     331
     332    PSP_INF_INFORMATION pInfo = (PSP_INF_INFORMATION)RTMemAllocZ(dwSize);
    350333    AssertPtrReturn(pInfo, VERR_NO_MEMORY);
    351334    fRc = SetupGetInfInformationW(hInf, INFINFO_INF_SPEC_IS_HINF, pInfo, dwSize, NULL);
     
    354337        if (pInfo->InfStyle == INF_STYLE_WIN4)
    355338        {
     339            /*
     340             * We query all the keys and values for the given index.
     341             */
    356342            dwSize = 0;
    357343            fRc = SetupQueryInfVersionInformationW(pInfo, uIndex, NULL /* Key, NULL means all */,
     
    359345            if (fRc)
    360346            {
    361                 PRTUTF16 pwszInfo = (PRTUTF16)RTMemAlloc(dwSize * sizeof(RTUTF16));
    362                 if (pwszInfo)
     347                PRTUTF16 pwszzInfo = (PRTUTF16)RTMemAllocZ(dwSize * sizeof(RTUTF16));
     348                if (pwszzInfo)
    363349                {
    364350                    fRc = SetupQueryInfVersionInformationW(pInfo, uIndex, NULL /* Key, NULL means all */,
    365                                                            pwszInfo, dwSize, NULL);
     351                                                           pwszzInfo, dwSize, NULL);
     352                    if (fRc)
     353                    {
     354                        /*
     355                         * Parse the block of "key1\0value1\0\key2\0\value2\0....\0\0" strings,
     356                         * snapping up stuff we know.
     357                         */
     358                        rc = VINF_SUCCESS;
     359                        size_t off  = 0;
     360                        while (off < dwSize)
     361                        {
     362                            PRTUTF16 const pwszKey = &pwszzInfo[off];
     363                            size_t const   cwcKey  = RTUtf16NLen(pwszKey, dwSize - off);
     364                            off += cwcKey + 1;
     365                            if (off >= dwSize)
     366                                break;
     367                            PRTUTF16 const pwszValue = &pwszzInfo[off];
     368                            size_t const   cwcValue  = RTUtf16NLen(pwszValue, dwSize - off);
     369                            off += cwcValue + 1;
    366370
    367371/** Macro to find a specific key and assign its value to the given string. */
    368 #define GET_VALUE(a_Key, a_String) \
    369     if (!RTUtf16ICmp(pwsz, a_Key)) \
     372#define GET_VALUE(a_wszKey, a_wszDst) \
     373    if (!RTUtf16ICmp(pwszKey, a_wszKey)) \
    370374    { \
    371         rc = RTUtf16Printf(a_String, RT_ELEMENTS(a_String), "%ls", pwsz + cch + 1 /* SKip key + terminator */); \
     375        rc = RTUtf16CopyEx(a_wszDst, RT_ELEMENTS(a_wszDst), pwszValue, cwcValue); \
    372376        AssertRCBreak(rc); \
    373377    }
    374                     PRTUTF16 pwsz = pwszInfo;
    375                     while (dwSize)
    376                     {
    377                         size_t const cch = RTUtf16Len(pwsz);
    378 
    379                         GET_VALUE(L"DriverVer", pVer->wszDriverVer);
    380                         GET_VALUE(L"Provider", pVer->wszProvider);
    381                         GET_VALUE(L"CatalogFile", pVer->wszCatalogFile);
    382 
    383                         dwSize -= (DWORD)cch + 1;
    384                         pwsz   += cch + 1;
     378                            GET_VALUE(L"DriverVer", pVer->wszDriverVer);
     379                            GET_VALUE(L"Provider", pVer->wszProvider);
     380                            GET_VALUE(L"CatalogFile", pVer->wszCatalogFile);
     381#undef GET_VALUE
     382                        }
     383                        Assert(off == dwSize);
    385384                    }
    386                     Assert(dwSize == 0);
    387 #undef GET_VALUE
    388                     RTMemFree(pwszInfo);
     385                    else
     386                        rc = VBoxWinDrvInstErrorFromWin32(GetLastError());
     387                    RTMemFree(pwszzInfo);
    389388                }
    390389                else
     
    411410 * @param   pVer                Where to return the Version section information on success.
    412411 */
    413 int VBoxWinDrvInfQuerySectionVer(HINF hInf, PVBOXWINDRVINFSEC_VERSION pVer)
     412int VBoxWinDrvInfQuerySectionVer(HINF hInf, PVBOXWINDRVINFSECVERSION pVer)
    414413{
    415414    return VBoxWinDrvInfQuerySectionVerEx(hInf, 0 /* uIndex */, pVer);
     
    427426{
    428427    HINF hInf = SetupOpenInfFileW(pwszInfFile, pwszClassName, INF_STYLE_WIN4, NULL /*__in PUINT ErrorLine */);
    429     if (hInf == INVALID_HANDLE_VALUE)
     428    *phInf = hInf;
     429    if (hInf != INVALID_HANDLE_VALUE)
    430430        return VBoxWinDrvInstErrorFromWin32(GetLastError());
    431 
    432     *phInf = hInf;
    433 
    434431    return VINF_SUCCESS;
    435432}
     
    446443int VBoxWinDrvInfOpen(PCRTUTF16 pwszInfFile, HINF *phInf)
    447444{
    448     int rc;
    449 
     445    int     rc;
    450446    GUID    guid = {};
    451     RTUTF16 pwszClassName[MAX_CLASS_NAME_LEN] = { };
    452     if (SetupDiGetINFClassW(pwszInfFile, &guid, &(pwszClassName[0]), sizeof(pwszClassName), NULL))
    453     {
    454         rc = VBoxWinDrvInfOpenEx(pwszInfFile, pwszClassName, phInf);
    455     }
     447    RTUTF16 wszClassName[MAX_CLASS_NAME_LEN] = {};
     448    if (SetupDiGetINFClassW(pwszInfFile, &guid, wszClassName, RT_ELEMENTS(wszClassName), NULL))
     449        rc = VBoxWinDrvInfOpenEx(pwszInfFile, wszClassName, phInf);
    456450    else
    457451        rc = VBoxWinDrvInstErrorFromWin32(GetLastError());
    458 
    459452    return rc;
    460453}
  • trunk/src/VBox/GuestHost/installation/VBoxWinDrvCommon.h

    r106890 r107901  
    6868int VBoxWinDrvInfQueryInstallSectionEx(HINF hInf, PCRTUTF16 pwszModel, PRTUTF16 *ppwszValue, PDWORD pcwcValue);
    6969int VBoxWinDrvInfQueryInstallSection(HINF hInf, PCRTUTF16 pwszModel, PRTUTF16 *ppwszValue);
    70 int VBoxWinDrvInfQuerySectionVerEx(HINF hInf, UINT uIndex, PVBOXWINDRVINFSEC_VERSION pVer);
    71 int VBoxWinDrvInfQuerySectionVer(HINF hInf, PVBOXWINDRVINFSEC_VERSION pVer);
     70int VBoxWinDrvInfQuerySectionVerEx(HINF hInf, UINT uIndex, PVBOXWINDRVINFSECVERSION pVer);
     71int VBoxWinDrvInfQuerySectionVer(HINF hInf, PVBOXWINDRVINFSECVERSION pVer);
    7272
    7373const char *VBoxWinDrvSetupApiErrToStr(const DWORD dwErr);
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