VirtualBox

Changeset 58050 in vbox for trunk/src


Ignore:
Timestamp:
Oct 6, 2015 1:16:06 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
103104
Message:

uri.cpp: Reformatted the code and found decoding statement. Must check result from rtUriPercentDecodeN.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/uri.cpp

    r58049 r58050  
    765765        && Parsed.cchPath)
    766766    {
    767         const char *pszPathOff = &pszUri[Parsed.offPath];
     767        /*
     768         * Calculate the size of the encoded result.
     769         */
    768770        size_t cbResult = 0;
    769771
    770772        /* Skip the leading slash if a DOS drive letter (e.g. "C:") is detected right after it. */
    771773        if (   Parsed.cchPath >= 3
    772             && pszPathOff[0]  == '/'        /* Leading slash. */
    773             && RT_C_IS_ALPHA(pszPathOff[1]) /* Drive letter. */
    774             && pszPathOff[2]  == ':')
     774            && pszUri[Parsed.offPath]  == '/'        /* Leading slash. */
     775            && RT_C_IS_ALPHA(pszUri[Parsed.offPath + 1]) /* Drive letter. */
     776            && pszUri[Parsed.offPath + 2]  == ':')
    775777        {
    776778            Parsed.offPath++;
    777779            Parsed.cchPath--;
    778             pszPathOff++;
    779         }
    780 
    781         if (uFormat == URI_FILE_FORMAT_WIN)
    782         {
    783             /* Authority given? */
    784             if (Parsed.cchAuthority)
    785             {
    786                 /* Include authority as part of UNC path. */
    787                 cbResult += 2; /* UNC slashes "\\". */
    788                 cbResult += Parsed.cchAuthority;
    789             }
     780        }
     781
     782        /* Windows: Authority given? Include authority as part of UNC path */
     783        if (uFormat == URI_FILE_FORMAT_WIN && Parsed.cchAuthority)
     784        {
     785            cbResult += 2; /* UNC slashes "\\". */
     786            cbResult += Parsed.cchAuthority;
    790787        }
    791788
     
    794791
    795792        /*
    796          * Compose string.
     793         * Compose encoded string.
    797794         */
    798795        char *pszResult;
     
    801798        {
    802799            size_t cbTmp = cbResult;
    803             if (uFormat == URI_FILE_FORMAT_WIN)
     800
     801            /* Windows: If an authority is given, add the required UNC prefix. */
     802            if (uFormat == URI_FILE_FORMAT_WIN && Parsed.cchAuthority)
    804803            {
    805                 /* If an authority is given, add the required UNC prefix. */
    806                 if (Parsed.cchAuthority)
    807                 {
    808                     rc = RTStrCatP(&pszTmp, &cbTmp, "\\\\");
    809                     if (RT_SUCCESS(rc))
    810 /** @todo r=bird: YOU MUST DECODE THE STRING!!  */
    811                         rc = RTStrCatPEx(&pszTmp, &cbTmp, &pszUri[Parsed.offAuthority], Parsed.cchAuthority);
    812                 }
     804                rc = RTStrCatP(&pszTmp, &cbTmp, "\\\\");
     805                if (RT_SUCCESS(rc))
     806                    rc = RTStrCatPEx(&pszTmp, &cbTmp, &pszUri[Parsed.offAuthority], Parsed.cchAuthority);
    813807            }
    814 
    815 /** @todo r=bird: YOU MUST DECODE THE STRING!!  */
    816808            if (RT_SUCCESS(rc))
    817809                rc = RTStrCatPEx(&pszTmp, &cbTmp, &pszUri[Parsed.offPath], Parsed.cchPath);
    818 
    819             if (RT_FAILURE(rc))
    820                 RTStrFree(pszResult);
    821         }
    822         else
    823             rc = VERR_NO_MEMORY;
    824         if (RT_SUCCESS(rc))
    825         {
    826             AssertPtr(pszResult);
    827             Assert(cbResult);
    828             char *pszPath = rtUriPercentDecodeN(pszResult, cbResult - 1 /* Minus termination */);
     810            AssertRC(rc); /* Shall not happen! */
     811            if (RT_SUCCESS(rc))
     812            {
     813                /*
     814                 * Decode the string and switch the slashes around the request way before returning.
     815                 */
     816                char *pszPath = rtUriPercentDecodeN(pszResult, cbResult - 1 /* Minus termination */);
     817                if (pszPath)
     818                {
     819                    RTStrFree(pszResult);
     820
     821                    if (uFormat == URI_FILE_FORMAT_UNIX)
     822                        return RTPathChangeToUnixSlashes(pszPath, true);
     823                    Assert(uFormat == URI_FILE_FORMAT_WIN);
     824                    return RTPathChangeToDosSlashes(pszPath, true);
     825                }
     826
     827                /* Failed. */
     828            }
    829829            RTStrFree(pszResult);
    830             if (uFormat == URI_FILE_FORMAT_UNIX)
    831                 return RTPathChangeToUnixSlashes(pszPath, true);
    832             Assert(uFormat == URI_FILE_FORMAT_WIN);
    833             return RTPathChangeToDosSlashes(pszPath, true);
    834         }
    835     }
    836 
     830        }
     831    }
    837832    return NULL;
    838833}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette