diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-04-27 03:03:26 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-04-27 03:03:26 +0200 |
commit | 96f3395cb8e2a48fef0a4018d1843e05341c4062 (patch) | |
tree | 65a207a3ae2f019b3a985c0bb5d0c86d7c62b81f /src | |
parent | 93c3948c1319f932b1af448e3d6a6a6ab668648e (diff) | |
parent | 72257654cc6f065f64c9218864e1be5f66738e8a (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: Ia2af053a10b3b33a3f73bd3d10636e33ad2519c4
Diffstat (limited to 'src')
-rw-r--r-- | src/mqtt/doc/qtmqtt.qdocconf | 1 | ||||
-rw-r--r-- | src/mqtt/qmqttconnection.cpp | 20 |
2 files changed, 16 insertions, 5 deletions
diff --git a/src/mqtt/doc/qtmqtt.qdocconf b/src/mqtt/doc/qtmqtt.qdocconf index 6fc50b4..aa72234 100644 --- a/src/mqtt/doc/qtmqtt.qdocconf +++ b/src/mqtt/doc/qtmqtt.qdocconf @@ -46,3 +46,4 @@ manifestmeta.thumbnail.names += "QtMqtt/WebSockets MQTT Subscription*" navigation.landingpage = "Qt MQTT" navigation.cppclassespage = "Qt MQTT C++ Classes" +navigation.homepage = "Qt for Automation" diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp index 6759306..bb27f66 100644 --- a/src/mqtt/qmqttconnection.cpp +++ b/src/mqtt/qmqttconnection.cpp @@ -79,7 +79,8 @@ QString QMqttConnection::readBufferTyped(qint64 *dataSize) const quint16 size = readBufferTyped<quint16>(dataSize); if (dataSize) *dataSize -= size; - return QString::fromUtf8(reinterpret_cast<const char *>(readBuffer(size).constData()), size); + const QByteArray ba = readBuffer(size); + return QString::fromUtf8(reinterpret_cast<const char *>(ba.constData()), ba.size()); } template<> @@ -88,7 +89,7 @@ QByteArray QMqttConnection::readBufferTyped(qint64 *dataSize) const quint16 size = readBufferTyped<quint16>(dataSize); if (dataSize) *dataSize -= size; - return QByteArray(reinterpret_cast<const char *>(readBuffer(size).constData()), size); + return readBuffer(size); } QMqttConnection::QMqttConnection(QObject *parent) : QObject(parent) @@ -305,13 +306,13 @@ bool QMqttConnection::sendControlConnect() if (m_clientPrivate->m_password.size()) packet.append(m_clientPrivate->m_password.toUtf8()); + m_internalState = BrokerWaitForConnectAck; + m_missingData = 0; + if (!writePacketToTransport(packet)) { qCDebug(lcMqttConnection) << "Could not write CONNECT frame to transport."; return false; } - - m_internalState = BrokerWaitForConnectAck; - m_missingData = 0; return true; } @@ -707,6 +708,10 @@ void QMqttConnection::transportError(QAbstractSocket::SocketError e) void QMqttConnection::readBuffer(char *data, quint64 size) { + if (Q_UNLIKELY(quint64(m_readBuffer.size() - m_readPosition) < size)) { + qCDebug(lcMqttConnection) << "Reaching out of buffer, protocol violation"; + closeConnection(QMqttClient::ProtocolViolation); + } memcpy(data, m_readBuffer.constData() + m_readPosition, size); m_readPosition += size; } @@ -750,6 +755,11 @@ void QMqttConnection::closeConnection(QMqttClient::ClientError error) QByteArray QMqttConnection::readBuffer(quint64 size) { + if (Q_UNLIKELY(quint64(m_readBuffer.size() - m_readPosition) < size)) { + qCDebug(lcMqttConnection) << "Reaching out of buffer, protocol violation"; + closeConnection(QMqttClient::ProtocolViolation); + return QByteArray(); + } QByteArray res(m_readBuffer.constData() + m_readPosition, int(size)); m_readPosition += size; return res; |