VirtualBox

Changeset 95857 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 26, 2022 11:54:38 PM (2 years ago)
Author:
vboxsync
Message:

VBoxService/Utils: Replaced sscanf with RTStrToUInt32Ex. bugref:10261

File:
1 edited

Legend:

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

    r93115 r95857  
    167167 * @returns Success indicator.
    168168 */
    169 static bool vgsvcUtilGetFileVersionOwn(LPSTR pVerData, PDWORD pdwMajor, PDWORD pdwMinor, PDWORD pdwBuildNumber,
    170                                        PDWORD pdwRevisionNumber)
     169static bool vgsvcUtilGetFileVersionOwn(LPSTR pVerData, uint32_t *puMajor, uint32_t *puMinor,
     170                                       uint32_t *puBuildNumber, uint32_t *puRevisionNumber)
    171171{
    172172    UINT    cchStrValue = 0;
     
    175175        return false;
    176176
    177     /** @todo r=bird: get rid of this. Avoid sscanf like the plague! */
    178     if (sscanf(pStrValue, "%ld.%ld.%ld.%ld", pdwMajor, pdwMinor, pdwBuildNumber, pdwRevisionNumber) != 4)
    179         return false;
     177    char *pszNext = pStrValue;
     178    int rc = RTStrToUInt32Ex(pszNext, &pszNext, 0, puMajor);
     179    AssertReturn(rc == VWRN_TRAILING_CHARS, false);
     180    AssertReturn(*pszNext == '.', false);
     181
     182    rc = RTStrToUInt32Ex(pszNext + 1, &pszNext, 0, puMinor);
     183    AssertReturn(rc == VWRN_TRAILING_CHARS, false);
     184    AssertReturn(*pszNext == '.', false);
     185
     186    rc = RTStrToUInt32Ex(pszNext + 1, &pszNext, 0, puBuildNumber);
     187    AssertReturn(rc == VWRN_TRAILING_CHARS, false);
     188    AssertReturn(*pszNext == '.', false);
     189
     190    rc = RTStrToUInt32Ex(pszNext + 1, &pszNext, 0, puRevisionNumber);
     191    AssertReturn(rc == VINF_SUCCESS || rc == VWRN_TRAILING_CHARS /*??*/, false);
    180192
    181193    return true;
     
    188200 * @returns VBox status code.
    189201 * @param   pszFilename         ASCII & ANSI & UTF-8 compliant name.
    190  * @param   pdwMajor            Where to return the major version number.
    191  * @param   pdwMinor            Where to return the minor version number.
    192  * @param   pdwBuildNumber      Where to return the build number.
    193  * @param   pdwRevisionNumber   Where to return the revision number.
    194  */
    195 static int vgsvcUtilGetFileVersion(const char *pszFilename, PDWORD pdwMajor, PDWORD pdwMinor, PDWORD pdwBuildNumber,
    196                                    PDWORD pdwRevisionNumber)
     202 * @param   puMajor             Where to return the major version number.
     203 * @param   puMinor             Where to return the minor version number.
     204 * @param   puBuildNumber       Where to return the build number.
     205 * @param   puRevisionNumber    Where to return the revision number.
     206 */
     207static int vgsvcUtilGetFileVersion(const char *pszFilename, uint32_t *puMajor, uint32_t *puMinor, uint32_t *puBuildNumber,
     208                                   uint32_t *puRevisionNumber)
    197209{
    198210    int rc;
    199211
    200     *pdwMajor = *pdwMinor = *pdwBuildNumber = *pdwRevisionNumber = 0;
     212    *puMajor = *puMinor = *puBuildNumber = *puRevisionNumber = 0;
    201213
    202214    /*
     
    217229                 * it goes beyond the range of an uint16_t / WORD.
    218230                 */
    219                 if (vgsvcUtilGetFileVersionOwn(pVerData, pdwMajor, pdwMinor, pdwBuildNumber, pdwRevisionNumber))
     231                if (vgsvcUtilGetFileVersionOwn(pVerData, puMajor, puMinor, puBuildNumber, puRevisionNumber))
    220232                    rc = VINF_SUCCESS;
    221233                else
     
    226238                    if (VerQueryValue(pVerData, "\\", (LPVOID *)&pFileInfo, &cbFileInfoIgnored))
    227239                    {
    228                         *pdwMajor          = HIWORD(pFileInfo->dwFileVersionMS);
    229                         *pdwMinor          = LOWORD(pFileInfo->dwFileVersionMS);
    230                         *pdwBuildNumber    = HIWORD(pFileInfo->dwFileVersionLS);
    231                         *pdwRevisionNumber = LOWORD(pFileInfo->dwFileVersionLS);
     240                        *puMajor          = HIWORD(pFileInfo->dwFileVersionMS);
     241                        *puMinor          = LOWORD(pFileInfo->dwFileVersionMS);
     242                        *puBuildNumber    = HIWORD(pFileInfo->dwFileVersionLS);
     243                        *puRevisionNumber = LOWORD(pFileInfo->dwFileVersionLS);
    232244                        rc = VINF_SUCCESS;
    233245                    }
     
    291303    if (RT_SUCCESS(rc))
    292304    {
    293         DWORD dwMajor, dwMinor, dwBuild, dwRev;
    294         rc = vgsvcUtilGetFileVersion(szFullPath, &dwMajor, &dwMinor, &dwBuild, &dwRev);
     305        uint32_t uMajor, uMinor, uBuild, uRev;
     306        rc = vgsvcUtilGetFileVersion(szFullPath, &uMajor, &uMinor, &uBuild, &uRev);
    295307        if (RT_SUCCESS(rc))
    296             RTStrPrintf(pszVersion, cbVersion, "%u.%u.%ur%u", dwMajor, dwMinor, dwBuild, dwRev);
     308            RTStrPrintf(pszVersion, cbVersion, "%u.%u.%ur%u", uMajor, uMinor, uBuild, uRev);
    297309    }
    298310    return rc;
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