tighten up message size checks

This commit is contained in:
arvidn 2019-03-20 10:12:42 +01:00 committed by Arvid Norberg
parent e435ffe04f
commit 01feb32821
1 changed files with 7 additions and 7 deletions

View File

@ -1238,7 +1238,7 @@ namespace {
INVARIANT_CHECK; INVARIANT_CHECK;
received_bytes(0, received); received_bytes(0, received);
if (!m_supports_fast) if (!m_supports_fast || m_recv_buffer.packet_size() != 5)
{ {
disconnect(errors::invalid_suggest, operation_t::bittorrent, peer_error); disconnect(errors::invalid_suggest, operation_t::bittorrent, peer_error);
return; return;
@ -1258,7 +1258,7 @@ namespace {
INVARIANT_CHECK; INVARIANT_CHECK;
received_bytes(0, received); received_bytes(0, received);
if (!m_supports_fast) if (!m_supports_fast || m_recv_buffer.packet_size() != 1)
{ {
disconnect(errors::invalid_have_all, operation_t::bittorrent, peer_error); disconnect(errors::invalid_have_all, operation_t::bittorrent, peer_error);
return; return;
@ -1271,7 +1271,7 @@ namespace {
INVARIANT_CHECK; INVARIANT_CHECK;
received_bytes(0, received); received_bytes(0, received);
if (!m_supports_fast) if (!m_supports_fast || m_recv_buffer.packet_size() != 1)
{ {
disconnect(errors::invalid_have_none, operation_t::bittorrent, peer_error); disconnect(errors::invalid_have_none, operation_t::bittorrent, peer_error);
return; return;
@ -1284,7 +1284,7 @@ namespace {
INVARIANT_CHECK; INVARIANT_CHECK;
received_bytes(0, received); received_bytes(0, received);
if (!m_supports_fast) if (!m_supports_fast || m_recv_buffer.packet_size() != 13)
{ {
disconnect(errors::invalid_reject, operation_t::bittorrent, peer_error); disconnect(errors::invalid_reject, operation_t::bittorrent, peer_error);
return; return;
@ -1308,7 +1308,7 @@ namespace {
INVARIANT_CHECK; INVARIANT_CHECK;
received_bytes(0, received); received_bytes(0, received);
if (!m_supports_fast) if (!m_supports_fast || m_recv_buffer.packet_size() != 5)
{ {
disconnect(errors::invalid_allow_fast, operation_t::bittorrent, peer_error); disconnect(errors::invalid_allow_fast, operation_t::bittorrent, peer_error);
return; return;
@ -1355,14 +1355,14 @@ namespace {
if (addr_type == 0) if (addr_type == 0)
{ {
if (int(recv_buffer.size()) < 2 + 4 + 2) return; if (int(recv_buffer.size()) != 2 + 4 + 2) return;
// IPv4 address // IPv4 address
ep = detail::read_v4_endpoint<tcp::endpoint>(ptr); ep = detail::read_v4_endpoint<tcp::endpoint>(ptr);
} }
else if (addr_type == 1) else if (addr_type == 1)
{ {
// IPv6 address // IPv6 address
if (int(recv_buffer.size()) < 2 + 18 + 2) return; if (int(recv_buffer.size()) != 2 + 18 + 2) return;
ep = detail::read_v6_endpoint<tcp::endpoint>(ptr); ep = detail::read_v6_endpoint<tcp::endpoint>(ptr);
} }
else else