VirtualBox

Changeset 78050 in vbox for trunk/src


Ignore:
Timestamp:
Apr 9, 2019 1:30:42 AM (6 years ago)
Author:
vboxsync
Message:

IPRT/dir: Lifting RTPATH_MAX restriction on RTDirOpen*. bugref:9172

Location:
trunk/src/VBox/Runtime
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/include/internal/dir.h

    r76585 r78050  
    175175 * @param   pDir                The directory to open. The pszPath member contains the
    176176 *                              path to the directory.
    177  * @param   pszPathBuf          Pointer to a RTPATH_MAX sized buffer containing
    178  *                              pszPath.  Find-first style systems can use this
    179  *                              to setup the wildcard expression.
    180177 * @param   hRelativeDir        The directory @a pvNativeRelative is relative,
    181178 *                              ~(uintptr_t)0 if absolute.
     
    183180 *                              we're to use (consume) hRelativeDir.
    184181 */
    185 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative);
     182int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative);
    186183
    187184/**
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r76553 r78050  
    527527     * As a sideeffect we also validate the path here.
    528528     */
    529     char   szRealPath[RTPATH_MAX + 1];
    530     int    rc;
     529    char  *pszAbsPath;
    531530    size_t cbFilter;                    /* includes '\0' (thus cb and not cch). */
    532531    size_t cucFilter0;                  /* includes U+0. */
     
    544543
    545544        cbFilter = cucFilter0 = 0;
    546         rc = RTPathAbs(pszPath, szRealPath, sizeof(szRealPath) - 1);
     545        pszAbsPath = RTPathAbsDup(pszPath);
    547546    }
    548547    else
     
    558557                return VERR_NO_MEMORY;
    559558            pszTmp[pszFilter - pszPath] = '\0';
    560             rc = RTPathAbs(pszTmp, szRealPath, sizeof(szRealPath) - 1);
     559            pszAbsPath = RTPathAbsDup(pszTmp);
    561560            RTStrFree(pszTmp);
    562561        }
    563562        else
    564             rc = RTPathReal(".", szRealPath, sizeof(szRealPath) - 1);
     563            pszAbsPath = RTPathAbsDup(".");
    565564        fDirSlash = true;
    566565    }
    567     if (RT_FAILURE(rc))
    568         return rc;
    569 
    570     /* add trailing '/' if missing. */
    571     size_t cchRealPath = strlen(szRealPath);
    572     if (!RTPATH_IS_SEP(szRealPath[cchRealPath - 1]))
    573     {
    574         szRealPath[cchRealPath++] = RTPATH_SLASH;
    575         szRealPath[cchRealPath] = '\0';
    576     }
     566    if (!pszAbsPath)
     567        return VERR_NO_MEMORY;
     568
     569
    577570
    578571    /*
     
    582575     * thus the horrible ugliness here. Solaris uses d_name[1] for instance.
    583576     */
    584     size_t cbDir = rtDirNativeGetStructSize(szRealPath);
    585     size_t const cbAllocated = cbDir
    586                              + cucFilter0 * sizeof(RTUNICP)
    587                              + cbFilter
    588                              + cchRealPath + 1 + 4;
     577    size_t const cchAbsPath      = strlen(pszAbsPath);
     578    size_t const cchAbsPathExtra = !RTPATH_IS_SEP(pszAbsPath[cchAbsPath - 1]) ? 1 : 0; /* add trailing '/' if missing */
     579    size_t const cbDir           = rtDirNativeGetStructSize(pszAbsPath);
     580    size_t const cbAllocated     = cbDir
     581                                 + cucFilter0 * sizeof(RTUNICP)
     582                                 + cbFilter
     583                                 + cchAbsPath + cchAbsPathExtra + 1 + 4;
    589584    PRTDIRINTERNAL pDir = (PRTDIRINTERNAL)RTMemAllocZ(cbAllocated);
    590585    if (!pDir)
     586    {
     587        RTStrFree(pszAbsPath);
    591588        return VERR_NO_MEMORY;
     589    }
    592590    uint8_t *pb = (uint8_t *)pDir + cbDir;
    593591
     
    598596    {
    599597        pDir->puszFilter = (PRTUNICP)pb;
    600         rc = RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter0, &pDir->cucFilter);
    601         AssertRC(rc);
     598        int rc2 = RTStrToUniEx(pszFilter, RTSTR_MAX, &pDir->puszFilter, cucFilter0, &pDir->cucFilter);
     599        AssertRC(rc2);
    602600        pb += cucFilter0 * sizeof(RTUNICP);
    603601        pDir->pszFilter = (char *)memcpy(pb, pszFilter, cbFilter);
     
    629627            break;
    630628    }
    631     pDir->cchPath       = cchRealPath;
    632     pDir->pszPath       = (char *)memcpy(pb, szRealPath, cchRealPath + 1);
    633     Assert(pb - (uint8_t *)pDir + cchRealPath + 1 <= cbAllocated);
     629    pDir->cchPath       = cchAbsPath + cchAbsPathExtra;
     630    pDir->pszPath       = (char *)memcpy(pb, pszAbsPath, cchAbsPath);
     631    pb[cchAbsPath]                   = RTPATH_SLASH;
     632    pb[cchAbsPath + cchAbsPathExtra] = '\0';
     633    Assert(pb - (uint8_t *)pDir + cchAbsPath + cchAbsPathExtra + 1 <= cbAllocated);
    634634    pDir->pszName       = NULL;
    635635    pDir->cchName       = 0;
     
    641641     * Hand it over to the native part.
    642642     */
    643     rc = rtDirNativeOpen(pDir, szRealPath, hRelativeDir, pvNativeRelative);
     643    int rc = rtDirNativeOpen(pDir, hRelativeDir, pvNativeRelative);
    644644    if (RT_SUCCESS(rc))
    645645        *phDir = pDir;
    646646    else
    647647        RTMemFree(pDir);
    648 
     648    RTStrFree(pszAbsPath);
    649649    return rc;
    650650}
  • trunk/src/VBox/Runtime/r3/nt/direnum-r3-nt.cpp

    r76553 r78050  
    8383
    8484
    85 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative)
     85int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative)
    8686{
    8787    /*
     
    130130        {
    131131            if (pvNativeRelative == NULL)
    132                 rc = RTNtPathOpenDir(pszPathBuf,
     132                rc = RTNtPathOpenDir(pDir->pszPath,
    133133                                     FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES | FILE_TRAVERSE | SYNCHRONIZE,
    134134                                     FILE_SHARE_READ | FILE_SHARE_WRITE,
  • trunk/src/VBox/Runtime/r3/posix/dir-posix.cpp

    r76895 r78050  
    242242
    243243
    244 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative)
    245 {
    246     NOREF(pszPathBuf); /* only used on windows */
     244int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative)
     245{
    247246    NOREF(hRelativeDir);
    248247    NOREF(pvNativeRelative);
  • trunk/src/VBox/Runtime/r3/win/direnum-win.cpp

    r76553 r78050  
    5151
    5252
    53 int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative))
     53int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative))
    5454{
    5555    RT_NOREF(hRelativeDir, pvNativeRelative);
     
    6262     * it when adding the wildcard expression.
    6363     */
     64/** @todo the pszPathBuf argument was removed in order to support paths longer than RTPATH_MAX.  Rewrite this code. */
    6465    size_t cbExpr;
    6566    const char *pszExpr;
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