aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-12-15 17:51:35 +0100
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-12-15 17:51:41 +0100
commitec6149c01e6dc5db26f81f47097537292ca79f35 (patch)
treeec07f5b3071415848b8f2bbc62a7e3e85a3677df /src
parent70150824dc2c0df97e5f7768734eeb0dde782d00 (diff)
parentf7264fff0a098f8b6354c7373b8790791c25dd07 (diff)
Merge #20616: Check CJDNS address is valid
f7264fff0a098f8b6354c7373b8790791c25dd07 Check if Cjdns address is valid (Lucas Ontivero) Pull request description: CJDNS addresses start with 0xFC and for that reason if a netaddr was unserialized with network type cjdns but its address prefix is not 0xFC then that netaddr should be considered invalid. ACKs for top commit: jonatack: ACK f7264fff0a098f8b6354c7373b8790791c25dd07 practicalswift: cr ACK f7264fff0a098f8b6354c7373b8790791c25dd07: patch looks correct theStack: ACK f7264fff0a098f8b6354c7373b8790791c25dd07 ✔️ Tree-SHA512: 5300df2ffbbd69c40271b6d8df96cca98eb3e1ee76aba62c9c76025d083788ab1f1332775890c63b06e02ca593863a867cd53956bce5962383e8450487898669
Diffstat (limited to 'src')
-rw-r--r--src/netaddress.cpp5
-rw-r--r--src/test/net_tests.cpp10
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