From c2ba553d878749c5664928c84bdc1e01206369c0 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 31 May 2018 11:02:06 +0200 Subject: [PATCH] Problem: unused values stored to variable, duplicated code Solution: remove duplicated and redundant code --- src/plain_server.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/plain_server.cpp b/src/plain_server.cpp index f9d7fe35..ff6eff3d 100644 --- a/src/plain_server.cpp +++ b/src/plain_server.cpp @@ -138,7 +138,7 @@ int zmq::plain_server_t::process_hello (msg_t *msg_) return -1; } const uint8_t username_length = *ptr++; - bytes_left -= 1; + bytes_left -= sizeof (username_length); if (bytes_left < username_length) { // PLAIN I: invalid PLAIN client, sent malformed username @@ -161,9 +161,10 @@ int zmq::plain_server_t::process_hello (msg_t *msg_) } const uint8_t password_length = *ptr++; - bytes_left -= 1; - if (bytes_left < password_length) { - // PLAIN I: invalid PLAIN client, sent malformed password + bytes_left -= sizeof (password_length); + if (bytes_left != password_length) { + // PLAIN I: invalid PLAIN client, sent malformed password or + // extraneous data session->get_socket ()->event_handshake_failed_protocol ( session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO); @@ -172,16 +173,6 @@ int zmq::plain_server_t::process_hello (msg_t *msg_) } const std::string password = std::string (ptr, password_length); - ptr += password_length; - bytes_left -= password_length; - if (bytes_left > 0) { - // PLAIN I: invalid PLAIN client, sent extraneous data - session->get_socket ()->event_handshake_failed_protocol ( - session->get_endpoint (), - ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO); - errno = EPROTO; - return -1; - } // Use ZAP protocol (RFC 27) to authenticate the user. rc = session->zap_connect ();