VirtualBox

Changeset 78048 in vbox for trunk/src/VBox/Runtime/generic


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

IPRT: Working on new RTPathAbsEx implementation, temporarily called RTPathAbsExEx. This should fix most of the bugs in the current RTPathAbs/Ex code and do away with the fixed path buffer limitations. Also introduces a RTPATH_BIG_MAX, given that RTPATH_MAX is just a reasonable and not absolute MAX value. The new one is more or less absolute and must never be used for stack buffers. bugref:9172

Location:
trunk/src/VBox/Runtime/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/RTPathAbs-generic.cpp

    r76553 r78048  
    4040#include "internal/fs.h"
    4141
     42#if 1
    4243
    4344static char *rtPathSkipRootSpec(char *pszCur)
     
    145146
    146147
    147 RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cchAbsPath)
     148RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cbAbsPath)
    148149{
    149150    int rc;
     
    163164    if (cchPath >= RTPATH_MAX)
    164165    {
    165         LogFlow(("RTPathAbs(%p:{%s}, %p, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath, cchAbsPath, VERR_FILENAME_TOO_LONG));
     166        LogFlow(("RTPathAbs(%p:{%s}, %p, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath, cbAbsPath, VERR_FILENAME_TOO_LONG));
    166167        return VERR_FILENAME_TOO_LONG;
    167168    }
     
    179180            || (cchTmpPath == 2 && szTmpPath[1] == RTPATH_SLASH))
    180181        {
    181             rc = RTPathGetCurrent(pszAbsPath, cchAbsPath);
     182            rc = RTPathGetCurrent(pszAbsPath, cbAbsPath);
    182183            if (RT_SUCCESS(rc))
    183184            {
     
    191192                    && (uintptr_t)&pszAbsPath[cch - 1] > (uintptr_t)pszTop && pszAbsPath[cch - 1] != RTPATH_SLASH)
    192193                {
    193                     if (cch + 1 < cchAbsPath)
     194                    if (cch + 1 < cbAbsPath)
    194195                    {
    195196                        pszAbsPath[cch++] = RTPATH_SLASH;
     
    274275        if (RT_FAILURE(rc))
    275276        {
    276             LogFlow(("RTPathAbs(%p:{%s}, %p, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath, cchAbsPath, rc));
     277            LogFlow(("RTPathAbs(%p:{%s}, %p, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath, cbAbsPath, rc));
    277278            return rc;
    278279        }
     
    360361     * Copy the result to the user buffer.
    361362     */
    362     if (cchTmpPath < cchAbsPath)
     363    if (cchTmpPath < cbAbsPath)
    363364    {
    364365        memcpy(pszAbsPath, szTmpPath, cchTmpPath + 1);
     
    369370
    370371    LogFlow(("RTPathAbs(%p:{%s}, %p:{%s}, %d): returns %Rrc\n", pszPath, pszPath, pszAbsPath,
    371              RT_SUCCESS(rc) ? pszAbsPath : "<failed>", cchAbsPath, rc));
     372             RT_SUCCESS(rc) ? pszAbsPath : "<failed>", cbAbsPath, rc));
    372373    return rc;
    373374}
    374375
     376#else
     377
     378RTDECL(int) RTPathAbs(const char *pszPath, char *pszAbsPath, size_t cbAbsPath)
     379{
     380    return RTPathAbsExEx(NULL, pszPath, RTPATH_STR_F_STYLE_HOST, pszAbsPath, &cbAbsPath);
     381}
     382
     383#endif
     384
  • trunk/src/VBox/Runtime/generic/RTPathGetCurrentDrive-generic.cpp

    r76553 r78048  
    3535#include <iprt/ctype.h>
    3636#include <iprt/err.h>
     37#include <iprt/mem.h>
    3738#include <iprt/string.h>
    3839#include "internal/path.h"
     
    4546     * Query the current directroy and extract the wanted information from it.
    4647     */
    47     int rc = RTPathGetCurrent(pszPath, cbPath);
     48    char *pszPathFree = NULL;
     49    char *pszCwd = pszPath;
     50    int rc = RTPathGetCurrent(pszCwd, cbPath);
     51    if (RT_SUCCESS(rc))
     52    { /* likely */ }
     53    else if (rc != VERR_BUFFER_OVERFLOW)
     54        return rc;
     55    else
     56    {
     57        pszPathFree = pszCwd = (char *)RTMemTmpAlloc(RTPATH_BIG_MAX);
     58        AssertReturn(pszPathFree, VERR_NO_TMP_MEMORY);
     59        rc = RTPathGetCurrent(pszCwd, RTPATH_BIG_MAX);
     60    }
    4861    if (RT_SUCCESS(rc))
    4962    {
     
    5164         * Drive letter? Chop off at root slash.
    5265         */
    53         if (pszPath[0] && RTPATH_IS_VOLSEP(pszPath[1]))
    54         {
    55             pszPath[2] = '\0';
    56             return rc;
    57         }
    58 
     66        if (pszCwd[0] && RTPATH_IS_VOLSEP(pszCwd[1]))
     67            pszCwd[2] = '\0';
    5968        /*
    6069         * UNC? Chop off after share.
    6170         */
    62         if (   RTPATH_IS_SLASH(pszPath[0])
    63             && RTPATH_IS_SLASH(pszPath[1])
    64             && !RTPATH_IS_SLASH(pszPath[2])
    65             && pszPath[2])
     71        else if (   RTPATH_IS_SLASH(pszCwd[0])
     72                 && RTPATH_IS_SLASH(pszCwd[1])
     73                 && !RTPATH_IS_SLASH(pszCwd[2])
     74                 && pszCwd[2])
    6675        {
    6776            /* Work thru the server name. */
    6877            size_t off = 3;
    69             while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off])
     78            while (!RTPATH_IS_SLASH(pszCwd[off]) && pszCwd[off])
    7079                off++;
    7180            size_t offServerSlash = off;
    7281
    7382            /* Is there a share name? */
    74             if (RTPATH_IS_SLASH(pszPath[off]))
     83            if (RTPATH_IS_SLASH(pszCwd[off]))
    7584            {
    76                 while (RTPATH_IS_SLASH(pszPath[off]))
     85                while (RTPATH_IS_SLASH(pszCwd[off]))
    7786                    off++;
    78                 if (pszPath[off])
     87                if (pszCwd[off])
    7988                {
    8089                    /* Work thru the share name. */
    81                     while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off])
     90                    while (!RTPATH_IS_SLASH(pszCwd[off]) && pszCwd[off])
    8291                        off++;
    8392                }
     
    8695                    off = offServerSlash;
    8796            }
     97            pszCwd[off] = '\0';
    8898        }
    89         return VERR_INTERNAL_ERROR_4;
     99        else
     100            rc = VERR_INTERNAL_ERROR_4;
     101    }
     102    if (pszPathFree)
     103    {
     104        if (RT_SUCCESS(rc))
     105            rc = RTStrCopy(pszPath, cbPath, pszCwd);
     106        RTMemTmpFree(pszPathFree);
    90107    }
    91108    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