mirror of
https://github.com/wownero/wownero.git
synced 2026-11-22 00:23:59 +01:00
Merge pull request #10958
ee8f546 rpc: recover from oversized ZMQ requests (selsta)
ACKs: jpk68, vtnerd
This commit is contained in:
+12
-7
@@ -144,22 +144,27 @@ namespace zmq
|
||||
static constexpr const int max_out = std::numeric_limits<int>::max();
|
||||
const std::string::size_type initial = payload.size();
|
||||
message part{};
|
||||
bool too_large = false;
|
||||
for (;;)
|
||||
{
|
||||
int last = 0;
|
||||
if ((last = zmq_msg_recv(part.handle(), socket, flags)) < 0)
|
||||
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());
|
||||
if (!too_large)
|
||||
too_large =
|
||||
max_message_size < payload.size() ||
|
||||
max_message_size - payload.size() < part.size();
|
||||
if (!too_large)
|
||||
payload.append(part.data(), part.size());
|
||||
if (!zmq_msg_more(part.handle()))
|
||||
break;
|
||||
}
|
||||
if (too_large)
|
||||
{
|
||||
errno = EMSGSIZE;
|
||||
return -1;
|
||||
}
|
||||
const std::string::size_type added = payload.size() - initial;
|
||||
return unsigned(max_out) < added ? max_out : int(added);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user