VirtualBox

Changeset 93479 in vbox for trunk/src


Ignore:
Timestamp:
Jan 28, 2022 3:04:07 PM (3 years ago)
Author:
vboxsync
Message:

VBoxNetAdpCtl: (bugref:8093) Added unicast and loopback checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp

    r93472 r93479  
    333333void AddressIPv4::deriveBroadcast(PCRTNETADDRIPV4 pcAddress, int iPrefix)
    334334{
    335     /* Note: the address is big-endian. */
    336335    RTNETADDRIPV4 mask, broadcast;
    337336    int rc = RTNetPrefixToMaskIPv4(iPrefix, &mask);
     
    773772        virtual const char *defaultNetwork() { return "192.168.56.1/21"; }; /* Matches defaults in VBox/Main/include/netif.h, see @bugref{10077}. */
    774773
     774    protected:
     775        bool isValidUnicastAddress(PCRTNETADDRIPV4 address);
     776
    775777    private:
    776778        RTNETADDRIPV4 m_address;
     
    794796        rc = RTNetStrToIPv4Cidr(pcszIpAddress, &m_address, &m_prefix);
    795797#endif
    796     m_fValid = RT_SUCCESS(rc);
     798    m_fValid = RT_SUCCESS(rc) && isValidUnicastAddress(&m_address);
     799}
     800
     801bool NetworkAddressIPv4::isValidUnicastAddress(PCRTNETADDRIPV4 address)
     802{
     803    /* Multicast addresses are not allowed. */
     804    if ((address->au8[0] & 0xF0) == 0xE0)
     805        return false;
     806
     807    /* Broadcast address is not allowed. */
     808    if (address->au32[0] == 0xFFFFFFFF) /* Endianess does not matter in this particual case. */
     809        return false;
     810
     811    /* Loopback addresses are not allowed. */
     812    if ((address->au8[0] & 0xFF) == 0x7F)
     813        return false;
     814
     815    return true;
    797816}
    798817
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