summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2020-02-27 05:23:39 +0300
committerKonstantin Ritt <ritt.ks@gmail.com>2020-04-02 02:36:02 +0300
commit17337160d9ac6b10e3b24f2c421b9f6db824c187 (patch)
tree6b348f9eb853576ee7f37539c2e4664b49b29ac2
parente37c80b52f93a8861ae93481fc672db3924c8f59 (diff)
Fix handling of incoming DISCONNECT Control packet
as of MQTT 5, DISCONNECT Control packet could be sent from the Client or the Server, however QMqttControlPacket::DISCONNECT wasn't handled in the switch, causing connection close with ProtocolViolation error. Change-Id: Ic908f4e51ad133aff90cac1c65aa6df7eb21a427 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r--src/mqtt/qmqttconnection.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp
index e7ea739..d5aef50 100644
--- a/src/mqtt/qmqttconnection.cpp
+++ b/src/mqtt/qmqttconnection.cpp
@@ -1828,6 +1828,25 @@ bool QMqttConnection::processDataHelper()
if (m_missingData == -1)
return false; // Connection closed inside readVariableByteInteger
break;
+ case QMqttControlPacket::DISCONNECT:
+ if (m_clientPrivate->m_protocolVersion != QMqttClient::MQTT_5_0) {
+ qCDebug(lcMqttConnection) << "Received unknown command.";
+ closeConnection(QMqttClient::ProtocolViolation);
+ return false;
+ }
+ qCDebug(lcMqttConnectionVerbose) << "Received DISCONNECT";
+ if ((m_currentPacket & 0x0F) != 0) {
+ qCDebug(lcMqttConnection) << "Malformed fixed header for DISCONNECT.";
+ closeConnection(QMqttClient::ProtocolViolation);
+ return false;
+ }
+ if (m_internalState != BrokerConnected) {
+ qCDebug(lcMqttConnection) << "Received DISCONNECT at unexpected time.";
+ closeConnection(QMqttClient::ProtocolViolation);
+ return false;
+ }
+ closeConnection(QMqttClient::NoError);
+ return false;
default:
qCDebug(lcMqttConnection) << "Received unknown command.";
closeConnection(QMqttClient::ProtocolViolation);