diff options
Diffstat (limited to '3rdparty/asio/include/asio/ip/impl/network_v6.ipp')
-rw-r--r-- | 3rdparty/asio/include/asio/ip/impl/network_v6.ipp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/3rdparty/asio/include/asio/ip/impl/network_v6.ipp b/3rdparty/asio/include/asio/ip/impl/network_v6.ipp index c2418e3e955..d85cd647e06 100644 --- a/3rdparty/asio/include/asio/ip/impl/network_v6.ipp +++ b/3rdparty/asio/include/asio/ip/impl/network_v6.ipp @@ -2,7 +2,7 @@ // ip/impl/network_v6.ipp // ~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) // Copyright (c) 2014 Oliver Kowalke (oliver dot kowalke at gmail dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying @@ -42,7 +42,7 @@ network_v6::network_v6(const address_v6& addr, unsigned short prefix_len) } } -ASIO_DECL address_v6 network_v6::network() const ASIO_NOEXCEPT +ASIO_DECL address_v6 network_v6::network() const noexcept { address_v6::bytes_type bytes(address_.to_bytes()); for (std::size_t i = 0; i < 16; ++i) @@ -55,7 +55,7 @@ ASIO_DECL address_v6 network_v6::network() const ASIO_NOEXCEPT return address_v6(bytes, address_.scope_id()); } -address_v6_range network_v6::hosts() const ASIO_NOEXCEPT +address_v6_range network_v6::hosts() const noexcept { address_v6::bytes_type begin_bytes(address_.to_bytes()); address_v6::bytes_type end_bytes(address_.to_bytes()); @@ -95,9 +95,12 @@ std::string network_v6::to_string() const std::string network_v6::to_string(asio::error_code& ec) const { + using namespace std; // For sprintf. ec = asio::error_code(); char prefix_len[16]; -#if defined(ASIO_HAS_SECURE_RTL) +#if defined(ASIO_HAS_SNPRINTF) + snprintf(prefix_len, sizeof(prefix_len), "/%u", prefix_length_); +#elif defined(ASIO_HAS_SECURE_RTL) sprintf_s(prefix_len, sizeof(prefix_len), "/%u", prefix_length_); #else // defined(ASIO_HAS_SECURE_RTL) sprintf(prefix_len, "/%u", prefix_length_); @@ -147,11 +150,21 @@ network_v6 make_network_v6(const std::string& str, return network_v6(); } - return network_v6(make_address_v6(str.substr(0, pos)), - std::atoi(str.substr(pos + 1).c_str())); + const address_v6 addr = make_address_v6(str.substr(0, pos), ec); + if (ec) + return network_v6(); + + const int prefix_len = std::atoi(str.substr(pos + 1).c_str()); + if (prefix_len < 0 || prefix_len > 128) + { + ec = asio::error::invalid_argument; + return network_v6(); + } + + return network_v6(addr, static_cast<unsigned short>(prefix_len)); } -#if defined(ASIO_HAS_STD_STRING_VIEW) +#if defined(ASIO_HAS_STRING_VIEW) network_v6 make_network_v6(string_view str) { @@ -164,7 +177,7 @@ network_v6 make_network_v6(string_view str, return make_network_v6(static_cast<std::string>(str), ec); } -#endif // defined(ASIO_HAS_STD_STRING_VIEW) +#endif // defined(ASIO_HAS_STRING_VIEW) } // namespace ip } // namespace asio |