VirtualBox

Changeset 8603 in vbox for trunk


Ignore:
Timestamp:
May 5, 2008 3:23:23 PM (17 years ago)
Author:
vboxsync
Message:

Return a COM error if there are invalid parameters

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r8602 r8603  
    16531653    Guid id = aId;
    16541654
    1655     if (id.isEmpty() || aBus == StorageBus_Null)
     1655    if (id.isEmpty())
    16561656        return E_INVALIDARG;
    16571657
    1658     /* The device property is not used for SATA yet. Thus it is always zero. */
    1659     if ((aBus == StorageBus_SATA) && (aDevice != 0))
    1660         AssertMsgFailed(("Invalid aDevice %d\n", aDevice)); /** @todo r=bird: You don't assert on bad input, you return E_FAIL or E_INVALIDARG via setError()! This is what is referred to in comments 9 and 5. */
     1658    if (aBus == StorageBus_SATA)
     1659    {
     1660        /* The device property is not used for SATA yet. Thus it is always zero. */
     1661        if (aDevice != 0)
     1662            return setError (E_INVALIDARG,
     1663                tr ("Invalid device number: %l (must be always 0)"),
     1664                    aDevice);
     1665
     1666        /*
     1667         * We suport 30 ports.
     1668         * @todo: r=aeichner make max port count a system property.
     1669         */
     1670        if ((aChannel < 0) || (aChannel >= 30))
     1671            return setError (E_INVALIDARG,
     1672                tr ("Invalid channel number: %l (must be in range [%lu, %lu])"),
     1673                    aChannel, 0, 29);
     1674    }
     1675    else if (aBus == StorageBus_IDE)
     1676    {
     1677        /* Validate input for IDE drives. */
     1678        if (aChannel == 0)
     1679        {
     1680            if ((aDevice < 0) || (aDevice > 1))
     1681                return setError (E_INVALIDARG,
     1682                    tr ("Invalid device number: %l (must be in range [%lu, %lu])"),
     1683                        aDevice, 0, 1);
     1684        }
     1685        else if (aChannel == 1)
     1686        {
     1687            /* The first device is assigned to the CD/DVD drive. */
     1688            if (aDevice != 1)
     1689                return setError (E_INVALIDARG,
     1690                    tr ("Invalid device number: %l (must be %lu)"),
     1691                        aDevice, 1);
     1692        }
     1693        else
     1694            return setError (E_INVALIDARG,
     1695                tr ("Invalid channel number: %l (must be in range [%lu, %lu])"),
     1696                    aChannel, 0, 1);
     1697    }
     1698    else
     1699        return E_INVALIDARG;
    16611700
    16621701    AutoCaller autoCaller (this);
  • trunk/src/VBox/Main/SATAControllerImpl.cpp

    r8155 r8603  
    235235{
    236236    LogFlowThisFunc (("aPortCount=%u\n", aPortCount));
     237
     238    /* We support a maximum of 30 channels. */
     239    if ((aPortCount < 1) || (aPortCount > 30))
     240        return setError (E_INVALIDARG,
     241            tr ("Invalid port count: %lu (must be in range [%lu, %lu])"),
     242                aPortCount, 1, 30);
    237243
    238244    AutoCaller autoCaller (this);
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