From f0bc2a3645466136483aee10f6df20710a08e872 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 3 Sep 2016 16:43:02 -0400 Subject: [PATCH] add null checks --- Datagram.cpp | 12 ++++++------ Datagram.h | 11 +++++++---- HTTPServer.cpp | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Datagram.cpp b/Datagram.cpp index 2247dff1..14f9f385 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -195,24 +195,24 @@ namespace datagram DatagramSession::Info DatagramSession::GetSessionInfo() const { if(!m_RoutingSession) - return DatagramSession::Info{nullptr, nullptr, m_LastUse, m_LastSuccess}; + return DatagramSession::Info(nullptr, nullptr, m_LastUse, m_LastSuccess); auto routingPath = m_RoutingSession->GetSharedRoutingPath(); if (!routingPath) - return DatagramSession::Info{nullptr, nullptr, m_LastUse, m_LastSuccess}; + return DatagramSession::Info(nullptr, nullptr, m_LastUse, m_LastSuccess); auto lease = routingPath->remoteLease; auto tunnel = routingPath->outboundTunnel; if(lease) { if(tunnel) - return DatagramSession::Info{lease->tunnelGateway, tunnel->GetEndpointIdentHash(), m_LastUse, m_LastSuccess}; + return DatagramSession::Info(lease->tunnelGateway, tunnel->GetEndpointIdentHash(), m_LastUse, m_LastSuccess); else - return DatagramSession::Info{lease->tunnelGateway, nullptr, m_LastUse, m_LastSuccess}; + return DatagramSession::Info(lease->tunnelGateway, nullptr, m_LastUse, m_LastSuccess); } else if(tunnel) - return DatagramSession::Info{nullptr, tunnel->GetEndpointIdentHash(), m_LastUse, m_LastSuccess}; + return DatagramSession::Info(nullptr, tunnel->GetEndpointIdentHash(), m_LastUse, m_LastSuccess); else - return DatagramSession::Info{nullptr, nullptr, m_LastUse, m_LastSuccess}; + return DatagramSession::Info(nullptr, nullptr, m_LastUse, m_LastSuccess); } void DatagramSession::HandleSend(std::shared_ptr msg) diff --git a/Datagram.h b/Datagram.h index add946f0..bc358a41 100644 --- a/Datagram.h +++ b/Datagram.h @@ -53,11 +53,14 @@ namespace datagram const uint64_t activity; const uint64_t success; Info() : IBGW(nullptr), OBEP(nullptr), activity(0), success(0) {} - Info(const i2p::data::IdentHash & ibgw, const i2p::data::IdentHash & obep, const uint64_t a, const uint64_t s) : - IBGW(new i2p::data::IdentHash(ibgw.data())), - OBEP(new i2p::data::IdentHash(obep.data())), + Info(const uint8_t * ibgw, const uint8_t * obep, const uint64_t a, const uint64_t s) : activity(a), - success(s) {} + success(s) { + if(ibgw) IBGW = new i2p::data::IdentHash(ibgw); + else IBGW = nullptr; + if(obep) OBEP = new i2p::data::IdentHash(obep); + else OBEP = nullptr; + } ~Info() { if(IBGW) delete IBGW; diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 56756277..f1e1e453 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -352,14 +352,14 @@ namespace http { s << "" << info.RemoteIdent.ToBase32() << ""; s << ""; if(info.CurrentIBGW) - s << info.CurrentIBGW->ToBase64(); + s << info.CurrentIBGW->ToBase64().c_str(); else s << "(none)"; s << ""; s << ""; if(info.CurrentOBEP) - s << info.CurrentOBEP->ToBase64(); + s << info.CurrentOBEP->ToBase64().c_str(); else s << "(none)"; s << "";