Browse Source

Merge pull request #1945 from chadf/fuzzing-2

Fixed division by zero due to thread race condition.
pull/1950/head
orignal 1 year ago committed by GitHub
parent
commit
5142459e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      libi2pd/NetDb.cpp
  2. 4
      libi2pd/Transports.cpp

4
libi2pd/NetDb.cpp

@ -1253,7 +1253,9 @@ namespace data @@ -1253,7 +1253,9 @@ namespace data
uint16_t inds[3];
RAND_bytes ((uint8_t *)inds, sizeof (inds));
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
inds[0] %= m_RouterInfos.size ();
auto count = m_RouterInfos.size ();
if(count == 0) return nullptr;
inds[0] %= count;
auto it = m_RouterInfos.begin ();
std::advance (it, inds[0]);
// try random router

4
libi2pd/Transports.cpp

@ -861,7 +861,9 @@ namespace transport @@ -861,7 +861,9 @@ namespace transport
uint16_t inds[3];
RAND_bytes ((uint8_t *)inds, sizeof (inds));
std::unique_lock<std::mutex> l(m_PeersMutex);
inds[0] %= m_Peers.size ();
auto count = m_Peers.size ();
if(count == 0) return nullptr;
inds[0] %= count;
auto it = m_Peers.begin ();
std::advance (it, inds[0]);
// try random peer

Loading…
Cancel
Save