tighten up validation of dont-have messages

This commit is contained in:
arvidn 2019-03-21 12:46:43 +01:00 committed by Arvid Norberg
parent 972288340f
commit b6896cf337
2 changed files with 11 additions and 1 deletions

View File

@ -1643,7 +1643,7 @@ namespace {
#endif
return;
}
piece_index_t const piece(aux::numeric_cast<int>(aux::read_uint32(recv_buffer)));
piece_index_t const piece(aux::read_int32(recv_buffer));
incoming_dont_have(piece);
return;
}

View File

@ -2034,6 +2034,16 @@ namespace libtorrent {
std::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
if (index < piece_index_t{}
|| index >= t->torrent_file().end_piece())
{
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::incoming, "DONT_HAVE"
, "invalid piece: %d", static_cast<int>(index));
#endif
return;
}
#ifndef TORRENT_DISABLE_EXTENSIONS
for (auto const& e : m_extensions)
{