diff options
| author | selsta <selsta@sent.at> | 2026-06-03 17:20:11 +0200 |
|---|---|---|
| committer | selsta <selsta@sent.at> | 2026-06-03 17:24:27 +0200 |
| commit | 93d792e63c85baec6f8a3b8f9bbad3f803dd3a7e (patch) | |
| tree | 0fa01d79f92de66dfa086cb4a7b1fa899f92dbfb /src | |
| parent | cb1b4b5321ce42bf1c51675398c97b70584b6a0c (diff) | |
| download | monzero-core-93d792e63c85baec6f8a3b8f9bbad3f803dd3a7e.tar.gz monzero-core-93d792e63c85baec6f8a3b8f9bbad3f803dd3a7e.tar.xz monzero-core-93d792e63c85baec6f8a3b8f9bbad3f803dd3a7e.zip | |
net: canonicalize Tor/I2P hosts during deserialization
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/i2p_address.cpp | 12 | ||||
| -rw-r--r-- | src/net/tor_address.cpp | 14 |
2 files changed, 17 insertions, 9 deletions
diff --git a/src/net/i2p_address.cpp b/src/net/i2p_address.cpp index 4e21085d0..72a449e2a 100644 --- a/src/net/i2p_address.cpp +++ b/src/net/i2p_address.cpp @@ -114,11 +114,15 @@ namespace net bool i2p_address::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent) { i2p_serialized in{}; - if (in._load(src, hparent) && in.host.size() < sizeof(host_) && (in.host == unknown_host || !host_check(in.host).has_error())) + if (in._load(src, hparent) && in.host.size() < sizeof(host_)) { - std::memcpy(host_, in.host.data(), in.host.size()); - std::memset(host_ + in.host.size(), 0, sizeof(host_) - in.host.size()); - return true; + net::canonicalize_host(in.host); + if (in.host == unknown_host || !host_check(in.host).has_error()) + { + std::memcpy(host_, in.host.data(), in.host.size()); + std::memset(host_ + in.host.size(), 0, sizeof(host_) - in.host.size()); + return true; + } } static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size"); std::memcpy(host_, unknown_host, sizeof(unknown_host)); // include null terminator diff --git a/src/net/tor_address.cpp b/src/net/tor_address.cpp index ac36dbffd..f1ad0b211 100644 --- a/src/net/tor_address.cpp +++ b/src/net/tor_address.cpp @@ -126,12 +126,16 @@ namespace net bool tor_address::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent) { tor_serialized in{}; - if (in._load(src, hparent) && in.host.size() < sizeof(host_) && (in.host == unknown_host || !host_check(in.host).has_error())) + if (in._load(src, hparent) && in.host.size() < sizeof(host_)) { - std::memcpy(host_, in.host.data(), in.host.size()); - std::memset(host_ + in.host.size(), 0, sizeof(host_) - in.host.size()); - port_ = in.port; - return true; + net::canonicalize_host(in.host); + if (in.host == unknown_host || !host_check(in.host).has_error()) + { + std::memcpy(host_, in.host.data(), in.host.size()); + std::memset(host_ + in.host.size(), 0, sizeof(host_) - in.host.size()); + port_ = in.port; + return true; + } } static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size"); std::memcpy(host_, unknown_host, sizeof(unknown_host)); // include null terminator |
