From 9a4ec1a5d095bbc1a674c951cd0329ebccf9247a Mon Sep 17 00:00:00 2001 From: selsta Date: Sun, 13 Sep 2026 20:12:04 +0200 Subject: [PATCH] wallet2: validate public node addresses before display (cherry picked from commit c683bf08850161d6b072fd70c0e1325cb39e0a61) --- src/simplewallet/simplewallet.cpp | 5 +++-- src/wallet/wallet2.cpp | 14 +++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 509fe4ac7..eb5aa8372 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -2345,8 +2345,9 @@ bool simple_wallet::public_nodes(const std::vector &args) const float cph = node.rpc_credits_per_hash / RPC_CREDITS_PER_HASH_SCALE; char cphs[9]; snprintf(cphs, sizeof(cphs), "%.3f", cph); - const std::string last_seen = node.last_seen == 0 ? tr("never") : get_human_readable_timespan(std::chrono::seconds(now - node.last_seen)); - std::string host = node.host + ":" + std::to_string(node.rpc_port); + const std::string last_seen = node.last_seen == 0 ? tr("never") : get_human_readable_timespan(std::chrono::seconds(now - std::min(now, node.last_seen))); + const std::string host = (node.host.find(':') == std::string::npos ? node.host : "[" + node.host + "]") + + ":" + std::to_string(node.rpc_port); message_writer() << boost::format("%32s %12s %16s") % host % cphs % last_seen; m_claimed_cph[host] = node.rpc_credits_per_hash; } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index e043e19a8..80db48f67 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -16400,7 +16400,19 @@ std::vector wallet2::get_public_nodes(bool white_only) nodes = res.white; nodes.reserve(nodes.size() + res.gray.size()); std::copy(res.gray.begin(), res.gray.end(), std::back_inserter(nodes)); - return nodes; + std::vector valid_nodes; + valid_nodes.reserve(nodes.size()); + for (auto &node: nodes) + { + if (node.rpc_port == 0) + continue; + const auto address = net::get_network_address(node.host, node.rpc_port); + if (!address || (node.host != address->host_str() && node.host != address->str())) + continue; + node.host = address->host_str(); + valid_nodes.push_back(std::move(node)); + } + return valid_nodes; } //---------------------------------------------------------------------------------------------------- std::pair wallet2::estimate_tx_size_and_weight(bool use_rct, int n_inputs, int ring_size, int n_outputs, size_t extra_size)