fix potential integer overflows and a typo in boost_version conditional

This commit is contained in:
Arvid Norberg 2012-02-27 06:26:11 +00:00
parent c168f9e1df
commit 30d02f6b7a
3 changed files with 6 additions and 3 deletions

View File

@ -58,8 +58,8 @@ namespace libtorrent
if (index == num_pieces()-1)
{
size_type size_except_last = num_pieces() - 1;
size_except_last *= piece_length();
int size = int(total_size() - size_except_last);
size_except_last *= size_type(piece_length());
size_type size = total_size() - size_except_last;
TORRENT_ASSERT(size > 0);
TORRENT_ASSERT(size <= piece_length());
return int(size);

View File

@ -1289,7 +1289,7 @@ namespace libtorrent
#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)
{
// if the cert wasn't signed by the correct CA, fail the verification

View File

@ -2839,6 +2839,9 @@ int utp_socket_impl::packet_timeout() const
// have an RTT estimate yet, make a conservative guess
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);
if (m_num_timeouts > 0) timeout += (1 << (int(m_num_timeouts) - 1)) * 1000;
return timeout;