VirtualBox

Changeset 64962 in vbox


Ignore:
Timestamp:
Dec 19, 2016 2:57:15 PM (8 years ago)
Author:
vboxsync
Message:

Main/VirtualBox: check VM name, must not be empty, plus sanity check for sanitiseMachineFilename()

File:
1 edited

Legend:

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

    r64955 r64962  
    13231323                                           com::Utf8Str       &aFile)
    13241324{
    1325     LogFlowThisFuncEnter();
     1325    if (RT_UNLIKELY(aName.isEmpty()))
     1326        return setError(E_INVALIDARG, tr("Machine name is invalid, must not be empty"));
    13261327
    13271328    Utf8Str strBase = aBaseFolder;
     
    13451346                fDirectoryIncludesUUID = (strValue == "1");
    13461347
    1347         } while(uPos != com::Utf8Str::npos);
     1348        } while (uPos != com::Utf8Str::npos);
    13481349    }
    13491350
     
    14291430    };
    14301431
    1431     char *pszName = strName.mutableRaw();
    1432     ssize_t cReplacements = RTStrPurgeComplementSet(pszName, s_uszValidRangePairs, '_');
    1433     Assert(cReplacements >= 0);
    1434     NOREF(cReplacements);
    1435 
    1436     /* No leading dot or dash. */
    1437     if (pszName[0] == '.' || pszName[0] == '-')
    1438         pszName[0] = '_';
    1439 
    1440     /* No trailing dot. */
    1441     if (pszName[strName.length() - 1] == '.')
    1442         pszName[strName.length() - 1] = '_';
    1443 
    1444     /* Mangle leading and trailing spaces. */
    1445     for (size_t i = 0; pszName[i] == ' '; ++i)
    1446         pszName[i] = '_';
    1447     for (size_t i = strName.length() - 1; i && pszName[i] == ' '; --i)
    1448         pszName[i] = '_';
     1432    if (!strName.isEmpty())
     1433    {
     1434        char *pszName = strName.mutableRaw();
     1435        ssize_t cReplacements = RTStrPurgeComplementSet(pszName, s_uszValidRangePairs, '_');
     1436        Assert(cReplacements >= 0);
     1437        NOREF(cReplacements);
     1438
     1439        /* No leading dot or dash. */
     1440        if (pszName[0] == '.' || pszName[0] == '-')
     1441            pszName[0] = '_';
     1442
     1443        /* No trailing dot. */
     1444        if (pszName[strName.length() - 1] == '.')
     1445            pszName[strName.length() - 1] = '_';
     1446
     1447        /* Mangle leading and trailing spaces. */
     1448        for (size_t i = 0; pszName[i] == ' '; ++i)
     1449            pszName[i] = '_';
     1450        for (size_t i = strName.length() - 1; i && pszName[i] == ' '; --i)
     1451            pszName[i] = '_';
     1452    }
    14491453}
    14501454
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