This commit is contained in:
Marcos Pinto 2008-01-07 01:36:09 +00:00
commit 294e1f6b76
6 changed files with 38 additions and 8 deletions

View file

@ -325,7 +325,7 @@ private:
l.unlock(); l.unlock();
t->expire_bandwidth(m_channel, qe.max_block_size); t->expire_bandwidth(m_channel, qe.max_block_size);
l.lock(); l.lock();
TORRENT_ASSERT(amount == limit - m_current_quota); amount = limit - m_current_quota;
continue; continue;
} }
@ -400,7 +400,7 @@ private:
l.lock(); l.lock();
add_history_entry(history_entry<PeerConnection, Torrent>( add_history_entry(history_entry<PeerConnection, Torrent>(
qe.peer, t, hand_out_amount, now + bw_window_size)); qe.peer, t, hand_out_amount, now + bw_window_size));
TORRENT_ASSERT(amount == limit - m_current_quota); amount = limit - m_current_quota;
} }
if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end()); if (!q.empty()) m_queue.insert(m_queue.begin(), q.begin(), q.end());
if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end()); if (!tmp.empty()) m_queue.insert(m_queue.begin(), tmp.begin(), tmp.end());

View file

@ -201,7 +201,7 @@ namespace libtorrent
for (std::list<socket_entry>::iterator i = m_sockets.begin() for (std::list<socket_entry>::iterator i = m_sockets.begin()
, end(m_sockets.end()); i != end; ++i) , end(m_sockets.end()); i != end; ++i)
{ {
if (!socket) continue; if (!i->socket) continue;
i->socket->close(); i->socket->close();
} }
} }

View file

@ -2668,6 +2668,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << "**ERROR**: " << error.message() << "[in peer_connection::on_receive_data]\n"; (*m_logger) << "**ERROR**: " << error.message() << "[in peer_connection::on_receive_data]\n";
#endif #endif
set_failed();
on_receive(error, bytes_transferred); on_receive(error, bytes_transferred);
throw std::runtime_error(error.message()); throw std::runtime_error(error.message());
} }
@ -2828,6 +2829,7 @@ namespace libtorrent
(*m_ses.m_logger) << "CONNECTION FAILED: " << m_remote.address().to_string() (*m_ses.m_logger) << "CONNECTION FAILED: " << m_remote.address().to_string()
<< ": " << e.message() << "\n"; << ": " << e.message() << "\n";
#endif #endif
set_failed();
m_ses.connection_failed(self(), m_remote, e.message().c_str()); m_ses.connection_failed(self(), m_remote, e.message().c_str());
return; return;
} }
@ -2888,6 +2890,7 @@ namespace libtorrent
#ifdef TORRENT_VERBOSE_LOGGING #ifdef TORRENT_VERBOSE_LOGGING
(*m_logger) << "**ERROR**: " << error.message() << " [in peer_connection::on_send_data]\n"; (*m_logger) << "**ERROR**: " << error.message() << " [in peer_connection::on_send_data]\n";
#endif #endif
set_failed();
throw std::runtime_error(error.message()); throw std::runtime_error(error.message());
} }
if (m_disconnecting) return; if (m_disconnecting) return;

View file

@ -1589,6 +1589,18 @@ namespace libtorrent
p->set_peer_info(0); p->set_peer_info(0);
TORRENT_ASSERT(i != m_connections.end()); TORRENT_ASSERT(i != m_connections.end());
m_connections.erase(i); m_connections.erase(i);
// remove from bandwidth request-queue
for (int c = 0; c < 2; ++c)
{
for (queue_t::iterator i = m_bandwidth_queue[c].begin()
, end(m_bandwidth_queue[c].end()); i != end; ++i)
{
if (i->peer != p) continue;
m_bandwidth_queue[c].erase(i);
break;
}
}
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -2605,6 +2617,9 @@ namespace libtorrent
{ {
session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); session_impl::mutex_t::scoped_lock l(m_ses.m_mutex);
TORRENT_ASSERT(m_bandwidth_queue[0].size() <= m_connections.size());
TORRENT_ASSERT(m_bandwidth_queue[1].size() <= m_connections.size());
int num_uploads = 0; int num_uploads = 0;
std::map<piece_block, int> num_requests; std::map<piece_block, int> num_requests;
for (const_peer_iterator i = begin(); i != end(); ++i) for (const_peer_iterator i = begin(); i != end(); ++i)

View file

@ -350,10 +350,23 @@ namespace libtorrent
{ m_name = info["name"].string(); } { m_name = info["name"].string(); }
fs::path tmp = m_name; fs::path tmp = m_name;
if (tmp.is_complete()) throw std::runtime_error("torrent contains " if (tmp.is_complete())
"a file with an absolute path: '" + m_name + "'"); {
if (tmp.has_branch_path()) throw std::runtime_error( m_name = tmp.leaf();
"torrent contains name with directories: '" + m_name + "'"); }
else if (tmp.has_branch_path())
{
fs::path p;
for (fs::path::iterator i = tmp.begin()
, end(tmp.end()); i != end; ++i)
{
if (*i == "." || *i == "..") continue;
p /= *i;
}
m_name = p.string();
}
if (m_name == ".." || m_name == ".")
throw std::runtime_error("invalid 'name' of torrent (possible exploit attempt)");
// extract file list // extract file list
entry const* i = info.find_key("files"); entry const* i = info.find_key("files");

View file

@ -106,7 +106,6 @@ namespace libtorrent
, udp::resolver::iterator i) try , udp::resolver::iterator i) try
{ {
if (error == asio::error::operation_aborted) return; if (error == asio::error::operation_aborted) return;
if (!m_socket.is_open()) return; // the operation was aborted
if (error || i == udp::resolver::iterator()) if (error || i == udp::resolver::iterator())
{ {
fail(-1, error.message().c_str()); fail(-1, error.message().c_str());