From 270072b09ec1e002f95b748463c26e34cd463b4a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 9 Sep 2018 18:26:53 +0200 Subject: [PATCH] Require shibboleth match at start of connection. --- client/TracyProfiler.cpp | 15 +++++++++++++++ common/TracyProtocol.hpp | 3 +++ server/TracyWorker.cpp | 2 ++ 3 files changed, 20 insertions(+) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 0eed8e7a..d099709d 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -913,6 +913,21 @@ void Profiler::Worker() if( m_sock ) break; } + { + timeval tv; + tv.tv_sec = 2; + tv.tv_usec = 0; + + char shibboleth[HandshakeShibbolethSize]; + const auto res = m_sock->ReadRaw( shibboleth, HandshakeShibbolethSize, &tv ); + if( !res || memcmp( shibboleth, HandshakeShibboleth, HandshakeShibbolethSize ) != 0 ) + { + m_sock->~Socket(); + tracy_free( m_sock ); + continue; + } + } + #ifdef TRACY_ON_DEMAND ClearQueues( token ); m_isConnected.store( true, std::memory_order_relaxed ); diff --git a/common/TracyProtocol.hpp b/common/TracyProtocol.hpp index f7275fab..f6701ddd 100644 --- a/common/TracyProtocol.hpp +++ b/common/TracyProtocol.hpp @@ -27,6 +27,9 @@ enum ServerQuery : uint8_t ServerQueryFrameName, }; +enum { HandshakeShibbolethSize = 8 }; +static const char HandshakeShibboleth[HandshakeShibbolethSize] = { 'T', 'r', 'a', 'c', 'y', 'P', 'r', 'f' }; + enum { WelcomeMessageProgramNameSize = 64 }; enum { WelcomeMessageHostInfoSize = 1024 }; diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 48f2ef9b..450a9585 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1279,6 +1279,8 @@ void Worker::Exec() if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break; } + m_sock.Send( HandshakeShibboleth, HandshakeShibbolethSize ); + auto lz4buf = std::make_unique( LZ4Size ); std::chrono::time_point t0;