fix: crash on corrupt dht.dat file (#2223)

This commit is contained in:
Charles Kerr 2021-11-25 02:59:44 -06:00 committed by GitHub
parent 3811f66a5c
commit 06090f113a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -324,14 +324,14 @@ int tr_dhtInit(tr_session* ss)
size_t len6 = 0;
if (ok)
{
uint8_t const* raw = nullptr;
have_id = tr_variantDictFindRaw(&benc, TR_KEY_id, &raw, &len);
if (have_id && len == 20)
auto sv = std::string_view{};
have_id = tr_variantDictFindStrView(&benc, TR_KEY_id, &sv);
if (have_id && std::size(sv) == 20)
{
memcpy(myid, raw, len);
std::copy(std::begin(sv), std::end(sv), myid);
}
uint8_t const* raw = nullptr;
if (ss->udp_socket != TR_BAD_SOCKET && tr_variantDictFindRaw(&benc, TR_KEY_nodes, &raw, &len) && len % 6 == 0)
{
nodes = static_cast<uint8_t*>(tr_memdup(raw, len));