Skip to content

Commit

Permalink
Merge pull request #1945 from chadf/fuzzing-2
Browse files Browse the repository at this point in the history
Fixed division by zero due to thread race condition.
  • Loading branch information
orignal authored Jul 10, 2023
2 parents 8590dbd + 638e9b4 commit 5142459
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion libi2pd/NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion libi2pd/Transports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5142459

Please sign in to comment.