net: Reject + sign when parsing subnet mask
It does not make sense and it is rejected by other parsers as well:
>>> ipaddress.ip_network("1.2.3.0/+24")
ValueError: '1.2.3.0/+24' does not appear to be an IPv4 or IPv6 network
This commit is contained in:
2 files changed
+3
-4
No files matched your search
+2
-3
@@ -829,10 +829,9 @@ CSubNet LookupSubNet(const std::string& subnet_str)
|
|||||||
addr = static_cast<CNetAddr>(MaybeFlipIPv6toCJDNS(CService{addr.value(), /*port=*/0}));
|
addr = static_cast<CNetAddr>(MaybeFlipIPv6toCJDNS(CService{addr.value(), /*port=*/0}));
|
||||||
if (slash_pos != subnet_str.npos) {
|
if (slash_pos != subnet_str.npos) {
|
||||||
const std::string netmask_str{subnet_str.substr(slash_pos + 1)};
|
const std::string netmask_str{subnet_str.substr(slash_pos + 1)};
|
||||||
uint8_t netmask;
|
if (const auto netmask{ToIntegral<uint8_t>(netmask_str)}) {
|
||||||
if (ParseUInt8(netmask_str, &netmask)) {
|
|
||||||
// Valid number; assume CIDR variable-length subnet masking.
|
// Valid number; assume CIDR variable-length subnet masking.
|
||||||
subnet = CSubNet{addr.value(), netmask};
|
subnet = CSubNet{addr.value(), *netmask};
|
||||||
} else {
|
} else {
|
||||||
// Invalid number; try full netmask syntax. Never allow lookup for netmask.
|
// Invalid number; try full netmask syntax. Never allow lookup for netmask.
|
||||||
const std::optional<CNetAddr> full_netmask{LookupHost(netmask_str, /*fAllowLookup=*/false)};
|
const std::optional<CNetAddr> full_netmask{LookupHost(netmask_str, /*fAllowLookup=*/false)};
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ BOOST_AUTO_TEST_CASE(embedded_test)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(subnet_test)
|
BOOST_AUTO_TEST_CASE(subnet_test)
|
||||||
{
|
{
|
||||||
|
|
||||||
BOOST_CHECK(LookupSubNet("1.2.3.0/24") == LookupSubNet("1.2.3.0/255.255.255.0"));
|
BOOST_CHECK(LookupSubNet("1.2.3.0/24") == LookupSubNet("1.2.3.0/255.255.255.0"));
|
||||||
BOOST_CHECK(LookupSubNet("1.2.3.0/24") != LookupSubNet("1.2.4.0/255.255.255.0"));
|
BOOST_CHECK(LookupSubNet("1.2.3.0/24") != LookupSubNet("1.2.4.0/255.255.255.0"));
|
||||||
BOOST_CHECK(LookupSubNet("1.2.3.0/24").Match(ResolveIP("1.2.3.4")));
|
BOOST_CHECK(LookupSubNet("1.2.3.0/24").Match(ResolveIP("1.2.3.4")));
|
||||||
@@ -185,6 +184,7 @@ BOOST_AUTO_TEST_CASE(subnet_test)
|
|||||||
// Check valid/invalid
|
// Check valid/invalid
|
||||||
BOOST_CHECK(LookupSubNet("1.2.3.0/0").IsValid());
|
BOOST_CHECK(LookupSubNet("1.2.3.0/0").IsValid());
|
||||||
BOOST_CHECK(!LookupSubNet("1.2.3.0/-1").IsValid());
|
BOOST_CHECK(!LookupSubNet("1.2.3.0/-1").IsValid());
|
||||||
|
BOOST_CHECK(!LookupSubNet("1.2.3.0/+24").IsValid());
|
||||||
BOOST_CHECK(LookupSubNet("1.2.3.0/32").IsValid());
|
BOOST_CHECK(LookupSubNet("1.2.3.0/32").IsValid());
|
||||||
BOOST_CHECK(!LookupSubNet("1.2.3.0/33").IsValid());
|
BOOST_CHECK(!LookupSubNet("1.2.3.0/33").IsValid());
|
||||||
BOOST_CHECK(!LookupSubNet("1.2.3.0/300").IsValid());
|
BOOST_CHECK(!LookupSubNet("1.2.3.0/300").IsValid());
|
||||||
|
|||||||
Reference in new issue
Block a user