VirtualBox

Changeset 97538 in vbox


Ignore:
Timestamp:
Nov 14, 2022 6:42:10 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
154568
Message:

Guest Control/Main: Some more fixes + more tests. bugref:10286

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp

    r97532 r97538  
    17551755     * 2    /gst/dir1    /dst/dir2/       /dst/dir2/dir1                    Copies dir1 into dir2.
    17561756     * 3    /gst/dir1    /dst/dir2        /dst/dir2                         Overwrites stuff from dir2 with stuff from dir1.
     1757     * 4    Dotdot ("..") directories are forbidden for security reasons.
    17571758     */
    17581759    const char *pszSrcName = RTPathFilenameEx(strSrcPath.c_str(),
     
    17781779    /* Translate the built destination path to a path compatible with the destination. */
    17791780    int vrc = GuestPath::Translate(strDstPath, enmSrcPathStyle, enmDstPathStyle);
     1781    if (RT_SUCCESS(vrc))
     1782    {
     1783        union
     1784        {
     1785            RTPATHPARSED    Parsed;
     1786            RTPATHSPLIT     Split;
     1787            uint8_t         ab[4096];
     1788        } u;
     1789        RTPATHPARSED Parsed;
     1790        vrc = RTPathParse(strDstPath.c_str(), &Parsed, sizeof(u),  enmDstPathStyle == PathStyle_DOS
     1791                                                                 ? RTPATH_STR_F_STYLE_DOS : RTPATH_STR_F_STYLE_UNIX);
     1792        if (RT_SUCCESS(vrc))
     1793        {
     1794            if (Parsed.fProps & RTPATH_PROP_DOTDOT_REFS) /* #4 */
     1795                vrc = VERR_INVALID_PARAMETER;
     1796        }
     1797    }
    17801798
    17811799    LogRel2(("Guest Control: Building destination path for '%s' (%s) -> '%s' (%s): %Rrc\n",
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r97531 r97538  
    17751775                }
    17761776
    1777                 /* Clean up the final host desitnation path. */
    1778                 vrc = GuestPath::Translate(strDstAbs, PATH_STYLE_NATIVE /* Source */, PATH_STYLE_NATIVE /* Dest */);
     1777                /* Translate the final host desitnation path. */
     1778                vrc = GuestPath::Translate(strDstAbs, mSession->i_getGuestPathStyle() /* Source */, PATH_STYLE_NATIVE /* Dest */);
    17791779                if (RT_FAILURE(vrc))
    17801780                {
     
    18521852                    }
    18531853                }
     1854            }
     1855
     1856            /* Translate the final host destination file path. */
     1857            vrc = GuestPath::Translate(strDstRootAbs,
     1858                                       mSession->i_getGuestPathStyle() /* Dest */, PATH_STYLE_NATIVE /* Source */);
     1859            if (RT_FAILURE(vrc))
     1860            {
     1861                setProgressErrorMsg(VBOX_E_IPRT_ERROR,
     1862                                    Utf8StrFmt(tr("Translating host destination path \"%s\" failed: %Rrc"),
     1863                                               strDstRootAbs.c_str(), vrc));
     1864                break;
    18541865            }
    18551866
     
    22372248
    22382249                /* Clean up the final host source path. */
    2239                 vrc = GuestPath::Translate(strSrcAbs, PATH_STYLE_NATIVE /* Source */, PATH_STYLE_NATIVE /* Dest */);
     2250                vrc = GuestPath::Translate(strSrcAbs, pList->mSourceSpec.enmPathStyle /* Source */,
     2251                                           pList->mSourceSpec.enmPathStyle /* Dest */);
    22402252                if (RT_FAILURE(vrc))
    22412253                {
     
    22462258                }
    22472259
    2248                 /* Clean up the final guest destination path. */
     2260                /* Translate final guest destination path. */
    22492261                vrc = GuestPath::Translate(strDstAbs,
    2250                                            mSession->i_getGuestPathStyle() /* Source */, mSession->i_getGuestPathStyle() /* Dest */);
     2262                                           PATH_STYLE_NATIVE /* Source */, mSession->i_getGuestPathStyle() /* Dest */);
    22512263                if (RT_FAILURE(vrc))
    22522264                {
     
    23302342            }
    23312343
    2332             /* Cleanup the destination path. */
     2344            /* Translate the final guest destination file path. */
    23332345            vrc = GuestPath::Translate(strDstRootAbs,
    2334                                        mSession->i_getGuestPathStyle() /* Source */,  mSession->i_getGuestPathStyle() /* Dest */);
     2346                                       PATH_STYLE_NATIVE /* Source */,  mSession->i_getGuestPathStyle() /* Dest */);
    23352347            if (RT_FAILURE(vrc))
    23362348            {
  • trunk/src/VBox/Main/testcase/tstGuestCtrlPaths.cpp

    r97304 r97538  
    4040
    4141
     42DECLINLINE(void) tstPathBuildDestination(const Utf8Str &strSrcPath, PathStyle_T enmSrcPathStyle,
     43                                         const Utf8Str &strDstPath, PathStyle_T enmDstPathStyle,
     44                                         int rcExp, Utf8Str strPathExp)
     45{
     46    Utf8Str strDstPath2 = strDstPath;
     47    int vrc = GuestPath::BuildDestinationPath(strSrcPath, enmSrcPathStyle, strDstPath2, enmDstPathStyle);
     48    RTTESTI_CHECK_MSG_RETV(vrc == rcExp, ("Expected %Rrc, got %Rrc for '%s'\n", rcExp, vrc, strDstPath.c_str()));
     49    RTTESTI_CHECK_MSG_RETV(strDstPath2 == strPathExp, ("Expected '%s', got '%s'\n", strPathExp.c_str(), strDstPath2.c_str()));
     50}
     51
    4252DECLINLINE(void) tstPathTranslate(Utf8Str strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle, int rcExp, Utf8Str strPathExp)
    4353{
    44     Utf8Str strPath2 = strPath; \
     54    Utf8Str strPath2 = strPath;
    4555    int vrc = GuestPath::Translate(strPath2, enmSrcPathStyle, enmDstPathStyle);
    4656    RTTESTI_CHECK_MSG_RETV(vrc == rcExp, ("Expected %Rrc, got %Rrc for '%s'\n", rcExp, vrc, strPath.c_str()));
     
    6878    RTAssertSetQuiet(true);
    6979
     80    /*
     81     * Path translation testing.
     82     */
    7083    tstPathTranslate("",    PathStyle_DOS,  PathStyle_DOS,  VINF_SUCCESS, "");
    7184
     
    89102    tstPathTranslate("foo/bar/dir with space/",    PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir with space/");
    90103
     104#if 0
    91105    /** Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows),
    92106      * however, on DOS "\" is a path separator.  See @bugref{21095} */
     
    96110    tstPathTranslate("foo/bar/2_dir_with_escape_sequence/the\\ \\ space", PathStyle_UNIX, PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\2_dir_with_escape_sequence\\the  space");
    97111    tstPathTranslate("foo/bar/dir_with_escape_sequence/spaces at end\\  \\ ", PathStyle_UNIX, PathStyle_DOS,  VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence\\spaces at end   ");
     112#endif
    98113
    99114    /* Filter out double slashes (cosmetic only). */
     
    102117
    103118    /* Mixed slashes. */
    104     tstPathTranslate("\\\\foo/bar\\\\baz",       PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "\\foo/bar\\baz");
     119    tstPathTranslate("\\\\foo/bar\\\\baz",       PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "\\\\foo/bar\\\\baz");
     120#if 0 /** @todo Not clear what to expect here. */
    105121    tstPathTranslate("with spaces\\ foo/\\ bar", PathStyle_UNIX, PathStyle_DOS,  VINF_SUCCESS, "with spaces foo\\ bar");
     122#endif
     123
     124    /*
     125     * Destination path building testing.
     126     */
     127    tstPathBuildDestination("", PathStyle_UNIX, "", PathStyle_UNIX, VERR_PATH_ZERO_LENGTH, "");
     128    tstPathBuildDestination(".", PathStyle_UNIX, ".", PathStyle_UNIX, VINF_SUCCESS, ".");
     129    tstPathBuildDestination("..", PathStyle_UNIX, "..", PathStyle_UNIX, VERR_INVALID_PARAMETER, "..");
     130    tstPathBuildDestination("/tmp/", PathStyle_UNIX, "/root/../foo", PathStyle_UNIX, VERR_INVALID_PARAMETER, "/root/../foo");
     131    /* ".." in actual file names are allowed. */
     132    tstPathBuildDestination("/tmp/", PathStyle_UNIX, "/root/foo..bar", PathStyle_UNIX, VINF_SUCCESS, "/root/foo..bar");
     133    /* Ditto for path names which consist of more than just "..". */
     134    tstPathBuildDestination("/tmp/", PathStyle_UNIX, "/root/foo..bar/baz", PathStyle_UNIX, VINF_SUCCESS, "/root/foo..bar/baz");
     135    tstPathBuildDestination("...", PathStyle_UNIX, "...", PathStyle_UNIX, VINF_SUCCESS, "...");
     136    tstPathBuildDestination("foo", PathStyle_UNIX, "bar", PathStyle_UNIX, VINF_SUCCESS, "bar");
     137    tstPathBuildDestination("foo/", PathStyle_UNIX, "bar/", PathStyle_UNIX, VINF_SUCCESS, "bar/");
     138    tstPathBuildDestination("foo/", PathStyle_UNIX, "bar/baz", PathStyle_UNIX, VINF_SUCCESS, "bar/baz");
     139    tstPathBuildDestination("foo/baz", PathStyle_UNIX, "bar/", PathStyle_UNIX, VINF_SUCCESS, "bar/baz");
     140    tstPathBuildDestination("foo/baz", PathStyle_UNIX, "bar\\", PathStyle_DOS, VINF_SUCCESS, "bar\\baz");
     141
     142    tstPathBuildDestination("c:\\temp\\", PathStyle_DOS, "/tmp/", PathStyle_UNIX, VINF_SUCCESS, "/tmp/");
     143    tstPathBuildDestination("c:\\TEMP\\", PathStyle_DOS, "/TmP/", PathStyle_UNIX, VINF_SUCCESS, "/TmP/");
     144    tstPathBuildDestination("c:\\temp\\foo.txt", PathStyle_DOS, "/tmp/foo.txt", PathStyle_UNIX, VINF_SUCCESS, "/tmp/foo.txt");
     145    tstPathBuildDestination("c:\\temp\\bar\\foo.txt", PathStyle_DOS, "/tmp/foo2.txt", PathStyle_UNIX, VINF_SUCCESS, "/tmp/foo2.txt");
     146    tstPathBuildDestination("c:\\temp\\bar\\foo3.txt", PathStyle_DOS, "/tmp/", PathStyle_UNIX, VINF_SUCCESS, "/tmp/foo3.txt");
     147
     148    tstPathBuildDestination("/tmp/bar/", PathStyle_UNIX, "c:\\temp\\", PathStyle_DOS, VINF_SUCCESS, "c:\\temp\\");
     149    tstPathBuildDestination("/tmp/BaR/", PathStyle_UNIX, "c:\\tEmP\\", PathStyle_DOS, VINF_SUCCESS, "c:\\tEmP\\");
     150    tstPathBuildDestination("/tmp/foo.txt", PathStyle_UNIX, "c:\\temp\\foo.txt", PathStyle_DOS, VINF_SUCCESS, "c:\\temp\\foo.txt");
     151    tstPathBuildDestination("/tmp/bar/foo.txt", PathStyle_UNIX, "c:\\temp\\foo2.txt", PathStyle_DOS, VINF_SUCCESS, "c:\\temp\\foo2.txt");
     152    tstPathBuildDestination("/tmp/bar/foo3.txt", PathStyle_UNIX, "c:\\temp\\", PathStyle_DOS, VINF_SUCCESS, "c:\\temp\\foo3.txt");
    106153
    107154    RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
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