Skip to content

Commit

Permalink
feat: check that no network has its default port set to a "bad" one
Browse files Browse the repository at this point in the history
Do this in CConnman's ctor instead of doing it for every addr we try to connect to
  • Loading branch information
UdjinM6 committed Jan 28, 2025
1 parent db7f4cf commit 8ee01a0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3540,9 +3540,6 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect, CDe
continue;
}

const uint16_t default_port{Params().GetDefaultPort(addr.GetNetwork())};
assert(!IsBadPort(default_port)); // Make sure we never set the default port to a bad port

// Do not connect to prohibited ports, unless 50 invalid addresses have been selected already.
if (nTries < 50 && IsBadPort(addr.GetPort())) {
continue;
Expand Down Expand Up @@ -4198,6 +4195,12 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In, AddrMan& addrman_in,
, nSeed0(nSeed0In)
, nSeed1(nSeed1In)
{
// Make sure we never set the default port to a bad port
for (int n = 0; n < NET_MAX; ++n) {
const bool is_bad_port = IsBadPort(Params().GetDefaultPort(static_cast<Network>(n)));
assert(!is_bad_port);
}

SetTryNewOutboundPeer(false);

Options connOptions;
Expand Down

0 comments on commit 8ee01a0

Please sign in to comment.