VirtualBox

Changeset 65611 in vbox


Ignore:
Timestamp:
Feb 4, 2017 1:20:20 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
113282
Message:

Main/DHCPServerImpl: Check that IP addresses are not all-zeroes or
all-ones of the subnet. Provide error messages too.

File:
1 edited

Legend:

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

    r65580 r65611  
    262262    rc = RTNetStrToIPv4Addr(aIPAddress.c_str(), &IPAddress);
    263263    if (RT_FAILURE(rc))
    264         return E_INVALIDARG;
     264        return mVirtualBox->setErrorBoth(E_INVALIDARG, rc,
     265                   "Invalid server address");
    265266
    266267    rc = RTNetStrToIPv4Addr(aNetworkMask.c_str(), &NetworkMask);
    267268    if (RT_FAILURE(rc))
    268         return E_INVALIDARG;
     269        return mVirtualBox->setErrorBoth(E_INVALIDARG, rc,
     270                   "Invalid netmask");
    269271
    270272    rc = RTNetStrToIPv4Addr(aLowerIP.c_str(), &LowerIP);
    271273    if (RT_FAILURE(rc))
    272         return E_INVALIDARG;
     274        return mVirtualBox->setErrorBoth(E_INVALIDARG, rc,
     275                   "Invalid range lower address");
    273276
    274277    rc = RTNetStrToIPv4Addr(aUpperIP.c_str(), &UpperIP);
    275278    if (RT_FAILURE(rc))
    276         return E_INVALIDARG;
     279        return mVirtualBox->setErrorBoth(E_INVALIDARG, rc,
     280                   "Invalid range upper address");
    277281
    278282    /*
     
    282286    rc = RTNetMaskToPrefixIPv4(&NetworkMask, NULL);
    283287    if (RT_FAILURE(rc))
    284         return E_INVALIDARG;
     288        return mVirtualBox->setErrorBoth(E_INVALIDARG, rc,
     289                   "Invalid netmask");
    285290
    286291    /* It's more convenient to convert to host order once */
     
    290295    UpperIP.u = RT_N2H_U32(UpperIP.u);
    291296
    292     /* Addresses must be unicast */
    293     if (   (IPAddress.u & 0xe0000000) == 0xe0000000
    294         || (LowerIP.u   & 0xe0000000) == 0xe0000000
    295         || (UpperIP.u   & 0xe0000000) == 0xe0000000)
    296     {
    297         return E_INVALIDARG;
    298     }
    299 
    300     /* Addresses should be from the same network */
    301     if (   (IPAddress.u & NetworkMask.u) != (LowerIP.u &NetworkMask.u)
    302         || (LowerIP.u & NetworkMask.u) != (UpperIP.u &NetworkMask.u))
    303     {
    304         return E_INVALIDARG;
     297    /*
     298     * Addresses must be unicast and from the same network
     299     */
     300    if (   (IPAddress.u & UINT32_C(0xe0000000)) == UINT32_C(0xe0000000)
     301        || (IPAddress.u & ~NetworkMask.u) == 0
     302        || ((IPAddress.u & ~NetworkMask.u) | NetworkMask.u) == UINT32_C(0xffffffff))
     303    {
     304        return mVirtualBox->setError(E_INVALIDARG,
     305                   "Invalid server address");
     306    }
     307
     308    if (   (LowerIP.u & UINT32_C(0xe0000000)) == UINT32_C(0xe0000000)
     309        || (LowerIP.u & NetworkMask.u) != (IPAddress.u &NetworkMask.u)
     310        || (LowerIP.u & ~NetworkMask.u) == 0
     311        || ((LowerIP.u & ~NetworkMask.u) | NetworkMask.u) == UINT32_C(0xffffffff))
     312    {
     313        return mVirtualBox->setError(E_INVALIDARG,
     314                   "Invalid range lower address");
     315    }
     316
     317    if (   (UpperIP.u & UINT32_C(0xe0000000)) == UINT32_C(0xe0000000)
     318        || (UpperIP.u & NetworkMask.u) != (IPAddress.u &NetworkMask.u)
     319        || (UpperIP.u & ~NetworkMask.u) == 0
     320        || ((UpperIP.u & ~NetworkMask.u) | NetworkMask.u) == UINT32_C(0xffffffff))
     321    {
     322        return mVirtualBox->setError(E_INVALIDARG,
     323                   "Invalid range upper address");
    305324    }
    306325
    307326    /* The range should be valid ... */
    308327    if (LowerIP.u > UpperIP.u)
    309         return E_INVALIDARG;
     328        return mVirtualBox->setError(E_INVALIDARG,
     329                   "Invalid range bounds");
    310330
    311331    /* ... and shouldn't contain the server's address */
    312332    if (LowerIP.u <= IPAddress.u && IPAddress.u <= UpperIP.u)
    313         return E_INVALIDARG;
    314 
     333        return mVirtualBox->setError(E_INVALIDARG,
     334                   "Server address within range bounds");
    315335
    316336    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
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