Skip to content

Commit f7264ff

Browse files
committed
Check if Cjdns address is valid
1 parent b76abae commit f7264ff

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/netaddress.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ bool CNetAddr::IsValid() const
437437
return false;
438438
}
439439

440+
// CJDNS addresses always start with 0xfc
441+
if (IsCJDNS() && (m_addr[0] != 0xFC)) {
442+
return false;
443+
}
444+
440445
// documentation IPv6 address
441446
if (IsRFC3849())
442447
return false;

src/test/net_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,16 @@ BOOST_AUTO_TEST_CASE(cnetaddr_unserialize_v2)
604604
BOOST_CHECK_EQUAL(addr.ToString(), "fc00:1:2:3:4:5:6:7");
605605
BOOST_REQUIRE(s.empty());
606606

607+
// Invalid CJDNS, wrong prefix.
608+
s << MakeSpan(ParseHex("06" // network type (CJDNS)
609+
"10" // address length
610+
"aa000001000200030004000500060007" // address
611+
));
612+
s >> addr;
613+
BOOST_CHECK(addr.IsCJDNS());
614+
BOOST_CHECK(!addr.IsValid());
615+
BOOST_REQUIRE(s.empty());
616+
607617
// Invalid CJDNS, with bogus length.
608618
s << MakeSpan(ParseHex("06" // network type (CJDNS)
609619
"01" // address length

0 commit comments

Comments
 (0)