VirtualBox

Changeset 24221 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Oct 30, 2009 10:20:40 PM (15 years ago)
Author:
vboxsync
Message:

RTPathAbsEx: some cleanup, addressed one todo item.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/path/RTPathAbsEx.cpp

    r21675 r24221  
    5757RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath)
    5858{
    59     if (pszBase && pszPath && !rtPathVolumeSpecLen(pszPath))
     59    if (    pszBase
     60        &&  pszPath
     61        &&  !rtPathVolumeSpecLen(pszPath)
     62       )
    6063    {
    6164#if defined(RT_OS_WINDOWS)
    6265        /* The format for very long paths is not supported. */
    63         if (    (pszBase[0] == '/' || pszBase[0] == '\\')
    64             &&  (pszBase[1] == '/' || pszBase[1] == '\\')
    65             &&   pszBase[2] == '?'
    66             &&  (pszBase[3] == '/' || pszBase[3] == '\\'))
     66        if (    RTPATH_IS_SLASH(pszBase[0])
     67            &&  RTPATH_IS_SLASH(pszBase[1])
     68            &&  pszBase[2] == '?'
     69            &&  RTPATH_IS_SLASH(pszBase[3])
     70           )
    6771            return VERR_INVALID_NAME;
    6872#endif
    6973
    7074        /** @todo there are a couple of things which isn't 100% correct, although the
    71          * current code will have to work for now - I don't have time to fix it right now.
     75         * current code will have to do for now, no time to fix.
    7276         *
    7377         * 1) On Windows & OS/2 we confuse '/' with an abspath spec and will
    7478         *    not necessarily resolve it on the right drive.
    7579         * 2) A trailing slash in the base might cause UNC names to be created.
    76          * 3) The lengths total doesn't have to be less than max length
    77          *    if the pszPath starts with a slash.
    7880         */
    79         size_t cchBase = strlen(pszBase);
    80         size_t cchPath = strlen(pszPath);
    81         if (cchBase + cchPath >= RTPATH_MAX)
    82             return VERR_FILENAME_TOO_LONG;
    83 
    84         bool fRootSpec = pszPath[0] == '/'
    85 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    86             || pszPath[0] == '\\'
    87 #endif
    88             ;
    89         size_t cchVolSpec = rtPathVolumeSpecLen(pszBase);
    90         char szPath[RTPATH_MAX];
    91         if (fRootSpec)
     81        size_t const cchPath = strlen(pszPath);
     82        char         szTmpPath[RTPATH_MAX];
     83        if (RTPATH_IS_SLASH(pszPath[0]))
    9284        {
    93             /* join the disk name from base and the path */
    94             memcpy(szPath, pszBase, cchVolSpec);
    95             strcpy(&szPath[cchVolSpec], pszPath);
     85            /* join the disk name from base and the path (DOS systems only) */
     86            size_t const cchVolSpec = rtPathVolumeSpecLen(pszBase);
     87            if (cchVolSpec + cchPath + 1 > sizeof(szTmpPath))
     88                return VERR_FILENAME_TOO_LONG;
     89            memcpy(szTmpPath, pszBase, cchVolSpec);
     90            memcpy(&szTmpPath[cchVolSpec], pszPath, cchPath + 1);
    9691        }
    9792        else
    9893        {
    9994            /* join the base path and the path */
    100             strcpy(szPath, pszBase);
    101             szPath[cchBase] = RTPATH_DELIMITER;
    102             strcpy(&szPath[cchBase + 1], pszPath);
     95            size_t const cchBase = strlen(pszBase);
     96            if (cchBase + 1 + cchPath + 1 > sizeof(szTmpPath))
     97                return VERR_FILENAME_TOO_LONG;
     98            memcpy(szTmpPath, pszBase, cchBase);
     99            szTmpPath[cchBase] = RTPATH_DELIMITER;
     100            memcpy(&szTmpPath[cchBase + 1], pszPath, cchPath + 1);
    103101        }
    104         return RTPathAbs(szPath, pszAbsPath, cchAbsPath);
     102        return RTPathAbs(szTmpPath, pszAbsPath, cchAbsPath);
    105103    }
    106104
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