aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2020-12-31 16:51:59 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2021-01-03 14:07:58 +0000
commit3c7eec152cd5663c461f64699574943d3619f0b9 (patch)
tree77fbfb324aff4ebee841dafb6b48466e7887852e /contrib
parentMerge pull request #7228 from vtnerd/fix/p2p_memory_usage_017 (diff)
downloadmonero-3c7eec152cd5663c461f64699574943d3619f0b9.tar.xz
add a max levin packet size by command type
Diffstat (limited to 'contrib')
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index f77f5d0a1..790b64aa5 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -434,7 +434,7 @@ public:
//async call scenario
boost::shared_ptr<invoke_response_handler_base> response_handler = m_invoke_response_handlers.front();
response_handler->reset_timer();
- MDEBUG(m_connection_context << "LEVIN_PACKET partial msg received. len=" << cb);
+ MDEBUG(m_connection_context << "LEVIN_PACKET partial msg received. len=" << cb << ", current total " << m_cache_in_buffer.size() << "/" << m_current_head.m_cb << " (" << (100.0f * m_cache_in_buffer.size() / (m_current_head.m_cb ? m_current_head.m_cb : 1)) << "%)");
}
}
break;
@@ -469,6 +469,14 @@ public:
temp = std::move(m_fragment_buffer);
m_fragment_buffer.clear();
std::memcpy(std::addressof(m_current_head), std::addressof(temp[0]), sizeof(bucket_head2));
+ const size_t max_bytes = m_connection_context.get_max_bytes(m_current_head.m_command);
+ if(m_current_head.m_cb > std::min<size_t>(max_packet_size, max_bytes))
+ {
+ MERROR(m_connection_context << "Maximum packet size exceed!, m_max_packet_size = " << std::min<size_t>(max_packet_size, max_bytes)
+ << ", packet header received " << m_current_head.m_cb << ", command " << m_current_head.m_command
+ << ", connection will be closed.");
+ return false;
+ }
buff_to_invoke = {reinterpret_cast<const uint8_t*>(temp.data()) + sizeof(bucket_head2), temp.size() - sizeof(bucket_head2)};
}
@@ -585,10 +593,11 @@ public:
m_cache_in_buffer.erase(sizeof(bucket_head2));
m_state = stream_state_body;
m_oponent_protocol_ver = m_current_head.m_protocol_version;
- if(m_current_head.m_cb > max_packet_size)
+ const size_t max_bytes = m_connection_context.get_max_bytes(m_current_head.m_command);
+ if(m_current_head.m_cb > std::min<size_t>(max_packet_size, max_bytes))
{
- LOG_ERROR_CC(m_connection_context, "Maximum packet size exceed!, m_max_packet_size = " << max_packet_size
- << ", packet header received " << m_current_head.m_cb
+ LOG_ERROR_CC(m_connection_context, "Maximum packet size exceed!, m_max_packet_size = " << std::min<size_t>(max_packet_size, max_bytes)
+ << ", packet header received " << m_current_head.m_cb << ", command " << m_current_head.m_command
<< ", connection will be closed.");
return false;
}