Skip to content

Commit 14c77fe

Browse files
committed
[STR-3621] Fix potential overflow in start index randomization
1 parent 6d5e67d commit 14c77fe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Socket/TCPClient.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
#include "TCPClient.h"
8-
#include <random>
98

109
CTCPClient::CTCPClient(const LogFnCallback oLogger, const SettingsFlag eSettings /*= ALL_FLAGS*/)
1110
: ASocket(oLogger, eSettings),
@@ -248,7 +247,10 @@ bool CTCPClient::Connect(const std::string& strServer, const std::string& strPor
248247
}
249248

250249
std::uniform_int_distribution<size_t> RngGen(0, uSize - 1);
251-
size_t uStartIndex = RngGen(m_Rng);
250+
size_t uStartIndex = 0;
251+
if (uSize > 0) {
252+
uStartIndex = RngGen(m_Rng);
253+
}
252254

253255
if (m_eSettingsFlags & ENABLE_LOG)
254256
m_oLog(StringFormat("[TCPClient][Info] Got %d addresses from getaddrinfo, starting from index %d", uSize,

0 commit comments

Comments
 (0)