Unverified Commit e8bb1cad authored by oneiric's avatar oneiric

Tunnel: check router profile before deref

Check that router profile exists before dereferencing the pointer.
parent 1616a39c
......@@ -242,7 +242,8 @@ bool RouterProfile::IsBad() {
std::shared_ptr<RouterProfile> GetRouterProfile(
const IdentHash& ident_hash) {
auto profile = std::make_shared<RouterProfile>(ident_hash);
profile->Load(); // if possible
if (profile) // sanity check if make_shared failed
profile->Load(); // if possible
return profile;
}
......
......@@ -163,7 +163,9 @@ bool Tunnel::HandleTunnelBuildResponse(
msg + 1 + hop->GetRecordIndex() * TUNNEL_BUILD_RECORD_SIZE;
std::uint8_t ret = record[BUILD_RESPONSE_RECORD_RET_OFFSET];
LOG(debug) << "Tunnel: ret code=" << static_cast<int>(ret);
hop->GetCurrentRouter()->GetProfile()->TunnelBuildResponse(ret);
const auto profile = hop->GetCurrentRouter()->GetProfile();
if (profile)
profile->TunnelBuildResponse(ret);
if (ret)
// if any of participants declined the tunnel is not established
established = false;
......@@ -546,8 +548,9 @@ void Tunnels::ManagePendingTunnels(
if (config) {
auto hop = config->GetFirstHop();
while (hop) {
if (hop->GetCurrentRouter())
hop->GetCurrentRouter()->GetProfile()->TunnelNonReplied();
const auto profile = hop->GetCurrentRouter()->GetProfile();
if (profile)
profile->TunnelNonReplied();
hop = hop->GetNextHop();
}
}
......
......@@ -337,7 +337,7 @@ std::shared_ptr<const kovri::core::RouterInfo> TunnelPool::SelectNextHop(
auto hop = is_exploratory ?
kovri::core::netdb.GetRandomRouter(prev_hop) :
kovri::core::netdb.GetHighBandwidthRandomRouter(prev_hop);
if (!hop || hop->GetProfile ()->IsBad())
if (!hop || (hop && hop->GetProfile() && hop->GetProfile()->IsBad()))
hop = kovri::core::netdb.GetRandomRouter();
return hop;
}
......@@ -353,7 +353,7 @@ bool TunnelPool::SelectPeers(
m_NumOutboundHops;
if (kovri::core::transports.GetNumPeers() > 25) {
auto r = kovri::core::transports.GetRandomPeer();
if (r && !r->GetProfile()->IsBad()) {
if (r && r->GetProfile() && !r->GetProfile()->IsBad()) {
prev_hop = r;
hops.push_back(r);
num_hops--;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment