From 757f4d1881a0cf197da7e0e86ea4b241086e3d7e Mon Sep 17 00:00:00 2001 From: jpk68 Date: Sat, 25 Jul 2026 16:42:55 -0400 Subject: [PATCH] chore: fix issues found through static analysis --- libi2pd/Config.h | 3 +++ libi2pd/TunnelConfig.cpp | 14 +++++++++++--- libi2pd/TunnelConfig.h | 2 +- libi2pd_client/AddressBook.cpp | 2 +- libi2pd_client/MatchedDestination.cpp | 4 ++++ libi2pd_client/MatchedDestination.h | 1 + 6 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libi2pd/Config.h b/libi2pd/Config.h index 79463e65..47f3cdd9 100644 --- a/libi2pd/Config.h +++ b/libi2pd/Config.h @@ -83,7 +83,10 @@ namespace config { bool GetOption(const char *name, T& value) { if (!m_Options.count(name)) + { + value = T(); return false; + } value = m_Options[name].as(); return true; } diff --git a/libi2pd/TunnelConfig.cpp b/libi2pd/TunnelConfig.cpp index d31c8a5c..e23e0dde 100644 --- a/libi2pd/TunnelConfig.cpp +++ b/libi2pd/TunnelConfig.cpp @@ -178,7 +178,10 @@ namespace tunnel { // inbound CreatePeers (peers); - m_LastHop->SetNextIdent (i2p::context.GetIdentHash ()); + if (m_LastHop) + m_LastHop->SetNextIdent (i2p::context.GetIdentHash ()); + else + LogPrint (eLogError, "Tunnel: Can't create inbound tunnel config with no peers"); } TunnelConfig::TunnelConfig (const std::vector >& peers, @@ -188,8 +191,13 @@ namespace tunnel { // outbound CreatePeers (peers); - m_FirstHop->isGateway = false; - m_LastHop->SetReplyHop (replyTunnelID, replyIdent); + if (m_FirstHop && m_LastHop) + { + m_FirstHop->isGateway = false; + m_LastHop->SetReplyHop (replyTunnelID, replyIdent); + } + else + LogPrint (eLogError, "Tunnel: Can't create outbound tunnel config with no peers"); } void TunnelConfig::CreatePeers (const std::vector >& peers) diff --git a/libi2pd/TunnelConfig.h b/libi2pd/TunnelConfig.h index f83744a1..fc56a7b8 100644 --- a/libi2pd/TunnelConfig.h +++ b/libi2pd/TunnelConfig.h @@ -180,7 +180,7 @@ namespace tunnel private: - TunnelHopConfig * m_FirstHop, * m_LastHop; + TunnelHopConfig * m_FirstHop = nullptr, * m_LastHop = nullptr; i2p::data::RouterInfo::CompatibleTransports m_FarEndTransports; }; diff --git a/libi2pd_client/AddressBook.cpp b/libi2pd_client/AddressBook.cpp index cb08a895..24e06997 100644 --- a/libi2pd_client/AddressBook.cpp +++ b/libi2pd_client/AddressBook.cpp @@ -72,7 +72,7 @@ namespace client i2p::fs::HashedStorage storage; std::string etagsPath, indexPath, localPath; - bool m_IsPersist; + bool m_IsPersist = false; std::string m_HostsFile; // file to dump hosts.txt, empty if not used std::unordered_map, uint64_t> > m_FullAddressCache; // ident hash -> (full ident buffer, last access timestamp) std::mutex m_FullAddressCacheMutex; diff --git a/libi2pd_client/MatchedDestination.cpp b/libi2pd_client/MatchedDestination.cpp index f7599afc..1d1b5cbb 100644 --- a/libi2pd_client/MatchedDestination.cpp +++ b/libi2pd_client/MatchedDestination.cpp @@ -20,6 +20,10 @@ namespace client : RunnableClientDestination(keys, false, params), m_RemoteName(remoteName) {} + MatchedTunnelDestination::~MatchedTunnelDestination() + { + if (m_ResolveTimer) m_ResolveTimer->cancel (); + } void MatchedTunnelDestination::ResolveCurrentLeaseSet() { diff --git a/libi2pd_client/MatchedDestination.h b/libi2pd_client/MatchedDestination.h index 72e6a209..80c59713 100644 --- a/libi2pd_client/MatchedDestination.h +++ b/libi2pd_client/MatchedDestination.h @@ -24,6 +24,7 @@ namespace client MatchedTunnelDestination(const i2p::data::PrivateKeys& keys, const std::string & remoteName, const i2p::util::Mapping * params = nullptr); + ~MatchedTunnelDestination(); void Start(); void Stop();