VirtualBox

Ignore:
Timestamp:
Feb 16, 2012 2:56:18 PM (13 years ago)
Author:
vboxsync
Message:

Main and FE/Qt: do not put slashes, control characters and a few others into VM file names by default.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r39926 r40153  
    13191319     * If a non-null and non-empty base folder is specified, the default
    13201320     * machine folder will be used as a base folder.
     1321     * We sanitise the machine name to a safe white list of characters before
     1322     * using it.
    13211323     */
    13221324    Utf8Str strBase = aBaseFolder;
     1325    Utf8Str strName = aName;
     1326    /** Set of characters which should be safe for use in filenames: some basic
     1327     * ASCII, Unicode from Latin-1 alphabetic to the end of Hangul.  We try to
     1328     * skip anything that could count as a control character in Windows or
     1329     * *nix, or be otherwise difficult for shells to handle (I would have
     1330     * preferred to remove the space and brackets too).  We also remove all
     1331     * characters which need UTF-16 surrogate pairs for Windows's benefit. */
     1332    RTUNICP aCpSet[] =
     1333        { ' ', ' ', '(', ')', '-', '-', '0', '9', 'A', 'Z', 'a', 'z', '_', '_',
     1334          0xa0, 0xd7af, '\0' };
     1335    Assert(RTStrPurgeComplementSet(strName.mutableRaw(), aCpSet, '_') > 0);
    13231336    if (strBase.isEmpty())
    13241337        /* we use the non-full folder value below to keep the path relative */
     
    13271340    calculateFullPath(strBase, strBase);
    13281341
    1329     Bstr bstrSettingsFile = BstrFmt("%s%c%ls%c%ls.vbox",
     1342    Bstr bstrSettingsFile = BstrFmt("%s%c%s%c%s.vbox",
    13301343                                    strBase.c_str(),
    13311344                                    RTPATH_DELIMITER,
    1332                                     aName,
     1345                                    strName.c_str(),
    13331346                                    RTPATH_DELIMITER,
    1334                                     aName);
     1347                                    strName.c_str());
     1348
     1349#if 0  /* Try to get a unique name. */
     1350    for (unsigned i = 1; RTFileExists(bstrSettingsFile.c_str() && i < 100; ++i)
     1351        bstrSettingsFile = BstrFmt("%s%c%s%u%c%s%u.vbox",
     1352                                   strBase.c_str(),
     1353                                   RTPATH_DELIMITER,
     1354                                   strName.c_str(), i,
     1355                                   RTPATH_DELIMITER,
     1356                                   strName.c_str());
     1357#endif
    13351358
    13361359    bstrSettingsFile.detachTo(aFilename);
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