VirtualBox

Changeset 78153 in vbox for trunk/src/VBox/Runtime/r3/win


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/r3/win/path-win.cpp

    r76553 r78153  
    671671    int rc;
    672672
    673     /*
    674      * GetCurrentDirectory may in some cases omit the drive letter, according
    675      * to MSDN, thus the GetFullPathName call.
    676      */
    677     RTUTF16 wszCurPath[RTPATH_MAX];
    678     if (GetCurrentDirectoryW(RTPATH_MAX, wszCurPath))
    679     {
    680         RTUTF16 wszFullPath[RTPATH_MAX];
    681         if (GetFullPathNameW(wszCurPath, RTPATH_MAX, wszFullPath, NULL))
    682             rc = RTUtf16ToUtf8Ex(&wszFullPath[0], RTSTR_MAX, &pszPath, cchPath, NULL);
     673    if (cchPath > 0)
     674    {
     675        /*
     676         * GetCurrentDirectory may in some cases omit the drive letter, according
     677         * to MSDN, thus the GetFullPathName call.
     678         */
     679        RTUTF16 wszCurPath[RTPATH_MAX];
     680        if (GetCurrentDirectoryW(RTPATH_MAX, wszCurPath))
     681        {
     682            RTUTF16 wszFullPath[RTPATH_MAX];
     683            if (GetFullPathNameW(wszCurPath, RTPATH_MAX, wszFullPath, NULL))
     684                rc = RTUtf16ToUtf8Ex(&wszFullPath[0], RTSTR_MAX, &pszPath, cchPath, NULL);
     685            else
     686                rc = RTErrConvertFromWin32(GetLastError());
     687        }
    683688        else
    684689            rc = RTErrConvertFromWin32(GetLastError());
    685690    }
    686691    else
    687         rc = RTErrConvertFromWin32(GetLastError());
     692        rc = VERR_BUFFER_OVERFLOW;
    688693    return rc;
    689694}
     
    724729RTDECL(int) RTPathGetCurrentOnDrive(char chDrive, char *pszPath, size_t cbPath)
    725730{
    726     WCHAR wszInput[4];
    727     wszInput[0] = chDrive;
    728     wszInput[1] = ':';
    729     wszInput[2] = '\0';
    730 
    731731    int rc;
    732     RTUTF16 wszFullPath[RTPATH_MAX];
    733     if (GetFullPathNameW(wszInput, RTPATH_MAX, wszFullPath, NULL))
    734         rc = RTUtf16ToUtf8Ex(&wszFullPath[0], RTSTR_MAX, &pszPath, cbPath, NULL);
     732    if (cbPath > 0)
     733    {
     734        WCHAR wszInput[4];
     735        wszInput[0] = chDrive;
     736        wszInput[1] = ':';
     737        wszInput[2] = '\0';
     738        RTUTF16 wszFullPath[RTPATH_MAX];
     739        if (GetFullPathNameW(wszInput, RTPATH_MAX, wszFullPath, NULL))
     740            rc = RTUtf16ToUtf8Ex(&wszFullPath[0], RTSTR_MAX, &pszPath, cbPath, NULL);
     741        else
     742            rc = RTErrConvertFromWin32(GetLastError());
     743    }
    735744    else
    736         rc = RTErrConvertFromWin32(GetLastError());
     745        rc = VERR_BUFFER_OVERFLOW;
    737746    return rc;
    738747}
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