mirror of
https://github.com/qt/qtmqtt.git
synced 2026-10-25 16:16:26 +00:00
Ensure valid read buffer when parsing the fixed header
Since the remaining length can be up to 4 bytes long make sure that there are enough bytes transmitted to parse the fix header correctly. Change-Id: I3830d3abb308c86048cac3a00a80067194caa482 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
parent
7b41e6039f
commit
460e466c3f
@ -735,8 +735,15 @@ void QMqttConnection::processData()
|
||||
m_missingData = 0;
|
||||
}
|
||||
|
||||
if (m_readBuffer.size() == 0)
|
||||
// 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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
readBuffer((char*)&m_currentPacket, 1);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user