From 95c4a87cccc46d96dde5f5f16071c6787e1f5c4d Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Wed, 24 Jun 2015 14:19:10 -0500 Subject: [PATCH] Check for invalid SAM destination This closes #208 --- SAM.cpp | 25 +++++++++++++++---------- SAM.h | 1 + 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/SAM.cpp b/SAM.cpp index cb2cac3e..7db1e1bb 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -343,19 +343,24 @@ namespace client if (m_Session) { i2p::data::IdentityEx dest; - dest.FromBase64 (destination); - context.GetAddressBook ().InsertAddress (dest); - auto leaseSet = m_Session->localDestination->FindLeaseSet (dest.GetIdentHash ()); - if (leaseSet) - Connect (leaseSet); - else + size_t len = dest.FromBase64(destination); + if (len > 0) { - m_Session->localDestination->RequestDestination (dest.GetIdentHash (), - std::bind (&SAMSocket::HandleConnectLeaseSetRequestComplete, - shared_from_this (), std::placeholders::_1)); + context.GetAddressBook().InsertAddress(dest); + auto leaseSet = m_Session->localDestination->FindLeaseSet(dest.GetIdentHash()); + if (leaseSet) + Connect(leaseSet); + else + { + m_Session->localDestination->RequestDestination(dest.GetIdentHash(), + std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, + shared_from_this(), std::placeholders::_1)); + } } + else + SendMessageReply(SAM_SESSION_STATUS_INVALID_KEY, strlen(SAM_SESSION_STATUS_INVALID_KEY), true); } - else + else SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true); } diff --git a/SAM.h b/SAM.h index d51f5aa3..7684d461 100644 --- a/SAM.h +++ b/SAM.h @@ -28,6 +28,7 @@ namespace client const char SAM_SESSION_CREATE_REPLY_OK[] = "SESSION STATUS RESULT=OK DESTINATION=%s\n"; const char SAM_SESSION_CREATE_DUPLICATED_ID[] = "SESSION STATUS RESULT=DUPLICATED_ID\n"; const char SAM_SESSION_CREATE_DUPLICATED_DEST[] = "SESSION STATUS RESULT=DUPLICATED_DEST\n"; + const char SAM_SESSION_STATUS_INVALID_KEY[] = "SESSION STATUS RESULT=INVALID_KEY\n"; const char SAM_STREAM_CONNECT[] = "STREAM CONNECT"; const char SAM_STREAM_STATUS_OK[] = "STREAM STATUS RESULT=OK\n"; const char SAM_STREAM_STATUS_INVALID_ID[] = "STREAM STATUS RESULT=INVALID_ID\n";