From 9640633dd1200b21997be7ce1fd5c2dbbd67dba1 Mon Sep 17 00:00:00 2001 From: Matej Ferencevic Date: Tue, 16 May 2017 10:40:11 +0200 Subject: [PATCH] Loosen up handshake size checks to accept javascript clients. Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D366 --- src/communication/bolt/v1/session.hpp | 4 ---- src/communication/bolt/v1/states/handshake.hpp | 6 +++--- tests/unit/bolt_session.cpp | 14 -------------- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/communication/bolt/v1/session.hpp b/src/communication/bolt/v1/session.hpp index 9b545b6bc..05a964247 100644 --- a/src/communication/bolt/v1/session.hpp +++ b/src/communication/bolt/v1/session.hpp @@ -85,10 +85,6 @@ class Session : public Loggable { } else if (buffer_.size() < HANDSHAKE_SIZE) { logger.debug("Received partial handshake of size {}", buffer_.size()); return; - } else if (buffer_.size() > HANDSHAKE_SIZE) { - logger.debug("Received too large handshake of size {}", buffer_.size()); - ClientFailureInvalidData(); - return; } else { logger.debug("Decoding handshake of size {}", buffer_.size()); } diff --git a/src/communication/bolt/v1/states/handshake.hpp b/src/communication/bolt/v1/states/handshake.hpp index 900e9f73e..38742788e 100644 --- a/src/communication/bolt/v1/states/handshake.hpp +++ b/src/communication/bolt/v1/states/handshake.hpp @@ -33,9 +33,9 @@ State StateHandshakeRun(Session &session) { } session.connected_ = true; - // Delete data from buffer. It is guaranteed that there will be exactly - // 20 bytes in the buffer so we can use buffer_.size() here. - session.buffer_.Shift(session.buffer_.size()); + // Delete data from buffer. It is guaranteed that there will more than, or + // equal to 20 bytes (HANDSHAKE_SIZE) in the buffer. + session.buffer_.Shift(HANDSHAKE_SIZE); return State::Init; } diff --git a/tests/unit/bolt_session.cpp b/tests/unit/bolt_session.cpp index fc878a66e..70fcdb47e 100644 --- a/tests/unit/bolt_session.cpp +++ b/tests/unit/bolt_session.cpp @@ -162,20 +162,6 @@ TEST(BoltSession, HandshakeInTwoPackets) { CheckOutput(output, handshake_resp, 4); } -TEST(BoltSession, HandshakeTooLarge) { - INIT_VARS; - - auto buff = session.Allocate(); - memcpy(buff.data, handshake_req, 20); - memcpy(buff.data + 20, handshake_req, 20); - session.Written(40); - session.Execute(); - - ASSERT_EQ(session.state_, StateT::Close); - ASSERT_FALSE(session.socket_.IsOpen()); - PrintOutput(output); - CheckFailureMessage(output); -} TEST(BoltSession, HandshakeWriteFail) { INIT_VARS;