diff options
author | Lucas Ontivero <lucasontivero@gmail.com> | 2020-12-10 14:26:58 -0300 |
---|---|---|
committer | Lucas Ontivero <lucasontivero@gmail.com> | 2020-12-14 14:48:52 -0300 |
commit | f7264fff0a098f8b6354c7373b8790791c25dd07 (patch) | |
tree | 5bf633a063956d53354a827d526d0267f4f9f549 | |
parent | b76abae387b9ac2526c315c95b0f2da8c78e16fc (diff) |
Check if Cjdns address is valid
-rw-r--r-- | src/netaddress.cpp | 5 | ||||
-rw-r--r-- | src/test/net_tests.cpp | 10 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp index 35e9161f58..b1f9d32d34 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -437,6 +437,11 @@ bool CNetAddr::IsValid() const return false; } + // CJDNS addresses always start with 0xfc + if (IsCJDNS() && (m_addr[0] != 0xFC)) { + return false; + } + // documentation IPv6 address if (IsRFC3849()) return false; diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index cec4a8df61..c86974ba5b 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -604,6 +604,16 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2) BOOST_CHECK_EQUAL(addr.ToString(), "fc00:1:2:3:4:5:6:7"); BOOST_REQUIRE(s.empty()); + // Invalid CJDNS, wrong prefix. + s << MakeSpan(ParseHex("06" // network type (CJDNS) + "10" // address length + "aa000001000200030004000500060007" // address + )); + s >> addr; + BOOST_CHECK(addr.IsCJDNS()); + BOOST_CHECK(!addr.IsValid()); + BOOST_REQUIRE(s.empty()); + // Invalid CJDNS, with bogus length. s << MakeSpan(ParseHex("06" // network type (CJDNS) "01" // address length |