net: cap aggregate ZMQ receive size

This commit is contained in:
selsta
2026-06-10 19:49:23 +02:00
parent a8478d21b2
commit d72cd7fc16
3 changed files with 10 additions and 2 deletions
+6
View File
@@ -150,6 +150,12 @@ namespace zmq
if ((last = zmq_msg_recv(part.handle(), socket, flags)) < 0) if ((last = zmq_msg_recv(part.handle(), socket, flags)) < 0)
return last; return last;
if (max_message_size < payload.size() ||
max_message_size - payload.size() < part.size())
{
errno = EMSGSIZE;
return -1;
}
payload.append(part.data(), part.size()); payload.append(part.data(), part.size());
if (!zmq_msg_more(part.handle())) if (!zmq_msg_more(part.handle()))
break; break;
+2
View File
@@ -64,6 +64,8 @@ namespace net
{ {
namespace zmq namespace zmq
{ {
constexpr std::size_t max_message_size = 10 * 1024 * 1024; // 10 MiB
//! \return Category for ZMQ errors. //! \return Category for ZMQ errors.
const std::error_category& error_category() noexcept; const std::error_category& error_category() noexcept;
+2 -2
View File
@@ -46,7 +46,7 @@ namespace cryptonote
namespace namespace
{ {
constexpr const int num_zmq_threads = 1; constexpr const int num_zmq_threads = 1;
constexpr const std::int64_t max_message_size = 10 * 1024 * 1024; // 10 MiB constexpr const std::int64_t max_frame_size = net::zmq::max_message_size;
constexpr const std::chrono::seconds linger_timeout{2}; // wait period for pending out messages constexpr const std::chrono::seconds linger_timeout{2}; // wait period for pending out messages
constexpr const int ipv6_option = 1; constexpr const int ipv6_option = 1;
@@ -63,7 +63,7 @@ namespace
return nullptr; return nullptr;
} }
if (zmq_setsockopt(out.get(), ZMQ_MAXMSGSIZE, std::addressof(max_message_size), sizeof(max_message_size)) != 0) if (zmq_setsockopt(out.get(), ZMQ_MAXMSGSIZE, std::addressof(max_frame_size), sizeof(max_frame_size)) != 0)
{ {
MONERO_LOG_ZMQ_ERROR("Failed to set maximum incoming message size"); MONERO_LOG_ZMQ_ERROR("Failed to set maximum incoming message size");
return nullptr; return nullptr;