Skip to content

Commit ec6149c

Browse files
committed
Merge #20616: Check CJDNS address is valid
f7264ff 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 f7264ff practicalswift: cr ACK f7264ff: patch looks correct theStack: ACK f7264ff ✔️ Tree-SHA512: 5300df2ffbbd69c40271b6d8df96cca98eb3e1ee76aba62c9c76025d083788ab1f1332775890c63b06e02ca593863a867cd53956bce5962383e8450487898669
2 parents 7015082 + f7264ff commit ec6149c

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)