made bdecode not throw

This commit is contained in:
Arvid Norberg 2008-06-23 22:00:27 +00:00
parent 92f13aea68
commit 4d380c57d7
5 changed files with 24 additions and 25 deletions

View File

@ -394,14 +394,7 @@ namespace libtorrent
bool err = false;
detail::bdecode_recursive(start, end, e, err, 0);
TORRENT_ASSERT(e.m_type_queried == false);
if (err)
{
#ifdef BOOST_NO_EXCEPTIONS
return entry();
#else
throw invalid_encoding();
#endif
}
if (err) return entry();
return e;
}
@ -414,14 +407,7 @@ namespace libtorrent
detail::bdecode_recursive(start, end, e, err, 0);
len = std::distance(s, start);
TORRENT_ASSERT(len >= 0);
if (err)
{
#ifdef BOOST_NO_EXCEPTIONS
return entry();
#else
throw invalid_encoding();
#endif
}
if (err) return entry();
return e;
}
}

View File

@ -226,13 +226,7 @@ namespace libtorrent
// handle tracker response
entry e;
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
e = bdecode(data, data + size);
#ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) {}
#endif
if (e.type() != entry::undefined_t)
{

View File

@ -444,6 +444,15 @@ namespace libtorrent { namespace dht
TORRENT_ASSERT(bytes_transferred > 0);
entry e = bdecode(buf, buf + bytes_transferred);
if (e.type() == entry::undefined_t)
{
#ifdef TORRENT_DHT_VERBOSE_LOGGING
std::string msg(buf, buf + bytes_transferred);
TORRENT_LOG(dht_tracker) << "invalid incoming packet: "
<< e.what() << "\n" << msg << "\n";
#endif
return;
}
#ifdef TORRENT_DHT_VERBOSE_LOGGING
std::stringstream log_line;

View File

@ -306,7 +306,7 @@ namespace libtorrent { namespace
if (length > 17 * 1024)
{
m_pc.disconnect("ut_metadata message larger than 17 kB");
m_pc.disconnect("ut_metadata message larger than 17 kB", 2);
return true;
}
@ -314,6 +314,11 @@ namespace libtorrent { namespace
int len;
entry msg = bdecode(body.begin, body.end, len);
if (msg.type() == entry::undefined_t)
{
m_pc.disconnect("invalid bencoding in ut_metadata message", 2);
return true;
}
int type = msg["msg_type"].integer();
int piece = msg["piece"].integer();
@ -364,7 +369,7 @@ namespace libtorrent { namespace
{
std::stringstream msg;
msg << "unknown ut_metadata extension message: " << type;
m_pc.disconnect(msg.str().c_str());
m_pc.disconnect(msg.str().c_str(), 2);
}
}
return true;

View File

@ -216,13 +216,18 @@ namespace libtorrent { namespace
if (length > 500 * 1024)
{
m_pc.disconnect("peer exchange message larger than 500 kB");
m_pc.disconnect("peer exchange message larger than 500 kB", 2);
return true;
}
if (body.left() < length) return true;
entry pex_msg = bdecode(body.begin, body.end);
if (pex_msg.type() == entry::undefined_t)
{
m_pc.disconnect("invalid bencoding in ut_metadata message", 2);
return true;
}
entry const* p = pex_msg.find_key("added");
entry const* pf = pex_msg.find_key("added.f");