mirror of
https://github.com/boostorg/asio.git
synced 2026-01-19 04:02:09 +00:00
Remove _FORTIFY_SOURCE workaround. Check size when processing addrinfo.
The previous workaround for _FORTIFY_SOURCE warnings increased the size of all IP endpoint objects. Instead, try fixing the warning at the point where it occurs, by limiting the length memcpy-ed while processing the addrinfo results from getaddrinfo.
This commit is contained in:
@@ -133,14 +133,20 @@ public:
|
||||
if (address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
|
||||
|| address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET6))
|
||||
{
|
||||
using namespace std; // For memcpy.
|
||||
typename InternetProtocol::endpoint endpoint;
|
||||
endpoint.resize(static_cast<std::size_t>(address_info->ai_addrlen));
|
||||
memcpy(endpoint.data(), address_info->ai_addr,
|
||||
address_info->ai_addrlen);
|
||||
results.values_->push_back(
|
||||
basic_resolver_entry<InternetProtocol>(endpoint,
|
||||
actual_host_name, service_name));
|
||||
const std::size_t expected_size =
|
||||
address_info->ai_family == BOOST_ASIO_OS_DEF(AF_INET)
|
||||
? sizeof(boost::asio::detail::sockaddr_in4_type)
|
||||
: sizeof(boost::asio::detail::sockaddr_in6_type);
|
||||
if (address_info->ai_addrlen >= expected_size)
|
||||
{
|
||||
using namespace std; // For memcpy.
|
||||
typename InternetProtocol::endpoint endpoint;
|
||||
endpoint.resize(expected_size);
|
||||
memcpy(endpoint.data(), address_info->ai_addr, expected_size);
|
||||
results.values_->push_back(
|
||||
basic_resolver_entry<InternetProtocol>(endpoint,
|
||||
actual_host_name, service_name));
|
||||
}
|
||||
}
|
||||
address_info = address_info->ai_next;
|
||||
}
|
||||
|
||||
@@ -60,13 +60,13 @@ public:
|
||||
// Get the underlying endpoint in the native type.
|
||||
boost::asio::detail::socket_addr_type* data() noexcept
|
||||
{
|
||||
return &data_.base[0];
|
||||
return &data_.base;
|
||||
}
|
||||
|
||||
// Get the underlying endpoint in the native type.
|
||||
const boost::asio::detail::socket_addr_type* data() const noexcept
|
||||
{
|
||||
return &data_.base[0];
|
||||
return &data_.base;
|
||||
}
|
||||
|
||||
// Get the underlying size of the endpoint in the native type.
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
// Determine whether the endpoint is IPv4.
|
||||
bool is_v4() const noexcept
|
||||
{
|
||||
return data_.base[0].sa_family == BOOST_ASIO_OS_DEF(AF_INET);
|
||||
return data_.base.sa_family == BOOST_ASIO_OS_DEF(AF_INET);
|
||||
}
|
||||
|
||||
#if !defined(BOOST_ASIO_NO_IOSTREAM)
|
||||
@@ -123,11 +123,7 @@ private:
|
||||
// The underlying IP socket address.
|
||||
union data_union
|
||||
{
|
||||
#if defined(_FORTIFY_SOURCE)
|
||||
boost::asio::detail::socket_addr_type base[8];
|
||||
#else // defined(_FORTIFY_SOURCE)
|
||||
boost::asio::detail::socket_addr_type base[1];
|
||||
#endif // defined(_FORTIFY_SOURCE)
|
||||
boost::asio::detail::socket_addr_type base;
|
||||
boost::asio::detail::sockaddr_in4_type v4;
|
||||
boost::asio::detail::sockaddr_in6_type v6;
|
||||
} data_;
|
||||
|
||||
Reference in New Issue
Block a user