Skip to content

Commit

Permalink
[net] Fix use of uninitialized value in getnetworkinfo(const JSONRPCR…
Browse files Browse the repository at this point in the history
…equest& request)
  • Loading branch information
practicalswift authored and furszy committed Nov 22, 2021
1 parent a13b7c9 commit 8c8ad18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
28 changes: 6 additions & 22 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,12 +1926,10 @@ CConnman::CConnman(uint64_t nSeed0In, uint64_t nSeed1In) : nSeed0(nSeed0In), nSe
nLastNodeId = 0;
nSendBufferMaxSize = 0;
nReceiveFloodSize = 0;
nMaxConnections = 0;
nMaxOutbound = 0;
nMaxAddnode = 0;
nBestHeight = 0;
clientInterface = nullptr;
flagInterruptMsgProc = false;

Options connOptions;
Init(connOptions);
}

NodeId CConnman::GetNewNodeId()
Expand Down Expand Up @@ -1969,25 +1967,13 @@ bool CConnman::InitBinds(const std::vector<CService>& binds, const std::vector<C
return fBound;
}

bool CConnman::Start(CScheduler& scheduler, Options connOptions)
bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
{
Init(connOptions);

nTotalBytesRecv = 0;
nTotalBytesSent = 0;

nRelevantServices = connOptions.nRelevantServices;
nLocalServices = connOptions.nLocalServices;
nMaxConnections = connOptions.nMaxConnections;
nMaxOutbound = std::min(connOptions.nMaxOutbound, nMaxConnections);
nMaxAddnode = connOptions.nMaxAddnode;
nMaxFeeler = connOptions.nMaxFeeler;

nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
nReceiveFloodSize = connOptions.nReceiveFloodSize;

SetBestHeight(connOptions.nBestHeight);

clientInterface = connOptions.uiInterface;

if (fListen && !InitBinds(connOptions.vBinds, connOptions.vWhiteBinds)) {
if (clientInterface) {
clientInterface->ThreadSafeMessageBox(
Expand All @@ -1997,8 +1983,6 @@ bool CConnman::Start(CScheduler& scheduler, Options connOptions)
return false;
}

vWhitelistedRange = connOptions.vWhitelistedRange;

for (const auto& strDest : connOptions.vSeedNodes) {
AddOneShot(strDest);
}
Expand Down
17 changes: 16 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,24 @@ class CConnman
bool m_use_addrman_outgoing = true;
std::vector<std::string> m_specified_outgoing;
};

void Init(const Options& connOptions) {
nLocalServices = connOptions.nLocalServices;
nRelevantServices = connOptions.nRelevantServices;
nMaxConnections = connOptions.nMaxConnections;
nMaxOutbound = std::min(connOptions.nMaxOutbound, connOptions.nMaxConnections);
nMaxAddnode = connOptions.nMaxAddnode;
nMaxFeeler = connOptions.nMaxFeeler;
nBestHeight = connOptions.nBestHeight;
clientInterface = connOptions.uiInterface;
nSendBufferMaxSize = connOptions.nSendBufferMaxSize;
nReceiveFloodSize = connOptions.nReceiveFloodSize;
vWhitelistedRange = connOptions.vWhitelistedRange;
}

CConnman(uint64_t seed0, uint64_t seed1);
~CConnman();
bool Start(CScheduler& scheduler, Options options);
bool Start(CScheduler& scheduler, const Options& options);
void Stop();
void Interrupt();
void OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant* grantOutbound = nullptr, const char* strDest = nullptr, bool fOneShot = false, bool fFeeler = false, bool fAddnode = false);
Expand Down

0 comments on commit 8c8ad18

Please sign in to comment.