Skip to content

Need stricter, OS-independent IPv4/IPv6 address parser #7435

@laanwj

Description

@laanwj

I'm not sure if this will be solved by libevent, it could be, in any case there needs to be an issue for this: currently CNetAddr (and to a lesser extent, CService) farm out address parsing to the OS, which causes it (at the discretion of the OS) to accept incomplete as well as otherwise invalid addresses.

@EthanHeilman perfectly illustrates this in #7291:

BOOST_CHECK(CNetAddr("1.1.1").ToString() == "1.1.0.1");
BOOST_CHECK(CNetAddr("1.1").ToString() == "1.0.0.1");
BOOST_CHECK(CNetAddr("1111").ToString() == "0.0.4.87");

Parsing incomplete addresses as they were complete ones causes confusion when specifying ban masks. For example a user may think that 1.1.1, as it is accepted, maps to 1.1.1.0/24. Mapping to 1.1.0.1 is just strange. It should simply reject these.

Also, CNetaddr is not supposed to accept a port! but parses this as IPv6 any addr:

BOOST_CHECK(CNetAddr("250.2.2.2:7777").ToString() == "::");
BOOST_CHECK(CNetAddr("1.1.1.1:1").ToString() == CNetAddr("2.2.2:1").ToString());

These cases too should result an address address that is not valid (!IsValid()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions