diff options
author | Lorenz Haas <lorenz.haas@histomatics.de> | 2017-12-03 14:08:22 +0100 |
---|---|---|
committer | Lorenz Haas <lorenz.haas@histomatics.de> | 2017-12-05 09:45:02 +0000 |
commit | 5746eeff1716af45f1d063c4100043a1a201ba81 (patch) | |
tree | bfb48d5ba8d20e0c1bc6a352a02aefcf4abf46fe | |
parent | 6b6d2749e6107a77390cc67572e86294115350a2 (diff) |
Fix test for fixed header completeness
The old test yield false if for example 3 bytes where received and the
second byte had no continuation bit but the third byte. In such a case
the third byte, however, is not part of the fixed header any more. Thus
the fixed header must considered complete.
Task-number: QTBUG-64965
Change-Id: Ie2853d11edeabc5ab3d06e98c3628af99a4d9ea8
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r-- | src/mqtt/qmqttconnection.cpp | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp index 622edba..09eeacd 100644 --- a/src/mqtt/qmqttconnection.cpp +++ b/src/mqtt/qmqttconnection.cpp @@ -756,12 +756,24 @@ void QMqttConnection::processData() // MQTT-2.2 A fixed header of a control packet must be at least 2 bytes. If the payload is // longer than 127 bytes the header can be up to 5 bytes long. - const int readBufferSize = m_readBuffer.size(); - if (readBufferSize < 2 - || (readBufferSize == 2 && (m_readBuffer.at(1) & 128) != 0) - || (readBufferSize == 3 && (m_readBuffer.at(2) & 128) != 0) - || (readBufferSize == 4 && (m_readBuffer.at(3) & 128) != 0)) { + switch (m_readBuffer.size()) { + case 0: + case 1: return; + case 2: + if ((m_readBuffer.at(1) & 128) != 0) + return; + break; + case 3: + if ((m_readBuffer.at(1) & 128) != 0 && (m_readBuffer.at(2) & 128) != 0) + return; + break; + case 4: + if ((m_readBuffer.at(1) & 128) != 0 && (m_readBuffer.at(2) & 128) != 0 && (m_readBuffer.at(3) & 128) != 0) + return; + break; + default: + break; } readBuffer((char*)&m_currentPacket, 1); |