forked from premiere/premiere-libtorrent
fix potential integer overflows and a typo in boost_version conditional
This commit is contained in:
parent
c168f9e1df
commit
30d02f6b7a
|
@ -58,8 +58,8 @@ namespace libtorrent
|
||||||
if (index == num_pieces()-1)
|
if (index == num_pieces()-1)
|
||||||
{
|
{
|
||||||
size_type size_except_last = num_pieces() - 1;
|
size_type size_except_last = num_pieces() - 1;
|
||||||
size_except_last *= piece_length();
|
size_except_last *= size_type(piece_length());
|
||||||
int size = int(total_size() - size_except_last);
|
size_type size = total_size() - size_except_last;
|
||||||
TORRENT_ASSERT(size > 0);
|
TORRENT_ASSERT(size > 0);
|
||||||
TORRENT_ASSERT(size <= piece_length());
|
TORRENT_ASSERT(size <= piece_length());
|
||||||
return int(size);
|
return int(size);
|
||||||
|
|
|
@ -1289,7 +1289,7 @@ namespace libtorrent
|
||||||
|
|
||||||
#ifdef TORRENT_USE_OPENSSL
|
#ifdef TORRENT_USE_OPENSSL
|
||||||
|
|
||||||
#if BOOST_VERSION > 104700
|
#if BOOST_VERSION >= 104700
|
||||||
bool torrent::verify_peer_cert(bool preverified, boost::asio::ssl::verify_context& ctx)
|
bool torrent::verify_peer_cert(bool preverified, boost::asio::ssl::verify_context& ctx)
|
||||||
{
|
{
|
||||||
// if the cert wasn't signed by the correct CA, fail the verification
|
// if the cert wasn't signed by the correct CA, fail the verification
|
||||||
|
|
|
@ -2839,6 +2839,9 @@ int utp_socket_impl::packet_timeout() const
|
||||||
// have an RTT estimate yet, make a conservative guess
|
// have an RTT estimate yet, make a conservative guess
|
||||||
if (m_state == UTP_STATE_NONE) return 3000;
|
if (m_state == UTP_STATE_NONE) return 3000;
|
||||||
|
|
||||||
|
// avoid overflow by simply capping based on number of timeouts as well
|
||||||
|
if (m_num_timeouts >= 7) return 60000;
|
||||||
|
|
||||||
int timeout = (std::max)(m_sm->min_timeout(), m_rtt.mean() + m_rtt.avg_deviation() * 2);
|
int timeout = (std::max)(m_sm->min_timeout(), m_rtt.mean() + m_rtt.avg_deviation() * 2);
|
||||||
if (m_num_timeouts > 0) timeout += (1 << (int(m_num_timeouts) - 1)) * 1000;
|
if (m_num_timeouts > 0) timeout += (1 << (int(m_num_timeouts) - 1)) * 1000;
|
||||||
return timeout;
|
return timeout;
|
||||||
|
|
Loading…
Reference in New Issue