VirtualBox

Ignore:
Timestamp:
Apr 17, 2019 12:30:08 PM (6 years ago)
Author:
vboxsync
Message:

IPRT: Added RTPATHABS_F_ENSURE_TRAILING_SLASH to RTPathAbsEx and fixed a couple of issues related to VERR_BUFFER_OVERFLOW code paths. bugref:9172

File:
1 edited

Legend:

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

    r78098 r78153  
    185185    {
    186186        Assert(pBaseParsed->cComps > 1);
    187         if (iLast >= 0 || (pParsed->fProps & RTPATH_PROP_DIR_SLASH))
     187        if (   iLast >= 0
     188            || (pParsed->fProps & RTPATH_PROP_DIR_SLASH)
     189            || (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH) )
    188190            pBaseParsed->fProps |= RTPATH_PROP_DIR_SLASH;
    189191        else
     
    191193    }
    192194
     195    /* Apply the trailing flash flag to the input path: */
     196    if (   iLast >= 0
     197        && (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH))
     198        pParsed->fProps |= RTPATH_PROP_DIR_SLASH;
     199
    193200    /*
    194201     * Combine the two.  RTPathParsedReassemble can handle in place stuff, as
     
    207214            rc = RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK,
    208215                                        &pszAbsPath[cchBaseInPlace], *pcbAbsPath - cchBaseInPlace);
    209             *pcbAbsPath = cchBaseInPlace + pParsed->cchPath;
    210216            if (RT_SUCCESS(rc))
     217            {
     218                *pcbAbsPath = cchBaseInPlace + pParsed->cchPath;
    211219                Assert(*pcbAbsPath == strlen(pszAbsPath));
     220            }
     221            else
     222                *pcbAbsPath = cchBaseInPlace + pParsed->cchPath + 1;
    212223        }
    213224        else
     
    219230        {
    220231            RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, pszAbsPath, 0);
    221             *pcbAbsPath = pBaseParsed->cchPath + pParsed->cchPath;
     232            *pcbAbsPath = pBaseParsed->cchPath + pParsed->cchPath + 1;
    222233        }
    223234        else
    224             *pcbAbsPath = pBaseParsed->cchPath;
     235            *pcbAbsPath = pBaseParsed->cchPath + 1;
    225236    }
    226237
     
    448459        i++;
    449460    }
     461
     462    /*
     463     * Before we continue, ensure trailing slash if requested.
     464     */
     465    if (   (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH)
     466        && iLast > 0)
     467        pParsed->fProps |= RTPATH_PROP_DIR_SLASH;
    450468
    451469    /*
     
    527545                {
    528546                    int rc2 = RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, pszAbsPath, 0);
    529                     Assert(rc2 == VERR_BUFFER_OVERFLOW); RT_NOREF(rc2);
     547                    Assert(rc2 == VERR_BUFFER_OVERFLOW);
    530548
    531549                    char *pszTmp = (char *)RTMemTmpAlloc(RTPATH_BIG_MAX);
    532550                    if (pszTmp)
    533551                    {
    534                         rc = RTPathGetCurrentDrive(pszTmp, RTPATH_BIG_MAX);
    535                         if (RT_SUCCESS(rc))
     552                        rc2 = RTPathGetCurrentDrive(pszTmp, RTPATH_BIG_MAX);
     553                        if (RT_SUCCESS(rc2))
    536554                            *pcbAbsPath = strlen(pszTmp) + pParsed->cchPath + 1;
    537555                        else
     
    570588                pParsed->aComps[i].cch = 0;
    571589    }
     590
     591    if (   (fFlags & RTPATHABS_F_ENSURE_TRAILING_SLASH)
     592        && pParsed->cComps > 1)
     593        pParsed->fProps |= RTPATH_PROP_DIR_SLASH;
     594
    572595    int rc = RTPathParsedReassemble(pszPath, pParsed, fFlags & RTPATH_STR_F_STYLE_MASK, pszAbsPath, *pcbAbsPath);
    573596    *pcbAbsPath = pParsed->cchPath + (rc == VERR_BUFFER_OVERFLOW);
     
    589612
    590613    AssertCompile(RTPATH_STR_F_STYLE_HOST == 0);
    591     AssertReturn(   RTPATH_STR_F_IS_VALID(fFlags, RTPATHABS_F_STOP_AT_BASE | RTPATHABS_F_STOP_AT_CWD)
     614    AssertReturn(   RTPATH_STR_F_IS_VALID(fFlags, RTPATHABS_F_STOP_AT_BASE | RTPATHABS_F_STOP_AT_CWD | RTPATHABS_F_ENSURE_TRAILING_SLASH)
    592615                 && !(fFlags & RTPATH_STR_F_MIDDLE), VERR_INVALID_FLAGS);
    593616    if ((fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_HOST)
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