diff options
| author | tobtoht <tob@featherwallet.org> | 2026-05-29 21:09:07 +0000 |
|---|---|---|
| committer | tobtoht <tob@featherwallet.org> | 2026-05-29 21:09:07 +0000 |
| commit | 54802803daca89250064ac05751f52e7a3f11b7d (patch) | |
| tree | f208b5b6537501041d4ae66f3e8559b40a1726e4 /src | |
| parent | 9da54d01008fc4c9ca1662e0210b479395c850e9 (diff) | |
| parent | 7d339778135c44370199f5c84e8c90b3d60f6717 (diff) | |
| download | monzero-core-54802803daca89250064ac05751f52e7a3f11b7d.tar.gz monzero-core-54802803daca89250064ac05751f52e7a3f11b7d.tar.xz monzero-core-54802803daca89250064ac05751f52e7a3f11b7d.zip | |
Merge pull request #10638
7d33977 net: canonicalize Tor and I2P hostnames (selsta)
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/host.h | 20 | ||||
| -rw-r--r-- | src/net/i2p_address.cpp | 7 | ||||
| -rw-r--r-- | src/net/tor_address.cpp | 7 |
3 files changed, 30 insertions, 4 deletions
diff --git a/src/net/host.h b/src/net/host.h new file mode 100644 index 000000000..c96a7b434 --- /dev/null +++ b/src/net/host.h @@ -0,0 +1,20 @@ +#pragma once + +#include <string> + +namespace net +{ + /*! + * \brief Canonicalize a hostname by converting letters to lowercase. + * + * \param host Hostname to canonicalize in-place. + */ + inline void canonicalize_host(std::string& host) noexcept + { + for (char& c : host) + { + if ('A' <= c && c <= 'Z') + c = static_cast<char>(c - 'A' + 'a'); + } + } +} diff --git a/src/net/i2p_address.cpp b/src/net/i2p_address.cpp index 4e21085d0..e793048c0 100644 --- a/src/net/i2p_address.cpp +++ b/src/net/i2p_address.cpp @@ -36,6 +36,7 @@ #include <limits> #include "net/error.h" +#include "net/host.h" #include "serialization/keyvalue_serialization.h" #include "storages/portable_storage.h" #include "string_tools_lexical.h" @@ -105,10 +106,12 @@ namespace net expect<i2p_address> i2p_address::make(const boost::string_ref address) { boost::string_ref host = address.substr(0, address.rfind(':')); - MONERO_CHECK(host_check(host)); + std::string normalized_host{host}; + net::canonicalize_host(normalized_host); + MONERO_CHECK(host_check(normalized_host)); static_assert(b32_length + sizeof(tld) == sizeof(i2p_address::host_), "bad internal host size"); - return i2p_address{host}; + return i2p_address{normalized_host}; } bool i2p_address::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent) diff --git a/src/net/tor_address.cpp b/src/net/tor_address.cpp index ac36dbffd..35bd8e9a2 100644 --- a/src/net/tor_address.cpp +++ b/src/net/tor_address.cpp @@ -37,6 +37,7 @@ #include <limits> #include "net/error.h" +#include "net/host.h" #include "serialization/keyvalue_serialization.h" #include "storages/portable_storage.h" #include "string_tools_lexical.h" @@ -112,7 +113,9 @@ namespace net const boost::string_ref port = address.substr(host.size() + (host.size() == address.size() ? 0 : 1)); - MONERO_CHECK(host_check(host)); + std::string normalized_host{host}; + net::canonicalize_host(normalized_host); + MONERO_CHECK(host_check(normalized_host)); std::uint16_t porti = default_port; if (!port.empty() && !epee::string_tools::get_xtype_from_string(porti, std::string{port})) @@ -120,7 +123,7 @@ namespace net static_assert(v2_length <= v3_length, "bad internal host size"); static_assert(v3_length + sizeof(tld) == sizeof(tor_address::host_), "bad internal host size"); - return tor_address{host, porti}; + return tor_address{normalized_host, porti}; } bool tor_address::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent) |
