diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-04-20 03:00:22 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-04-20 03:00:22 +0200 |
commit | 72257654cc6f065f64c9218864e1be5f66738e8a (patch) | |
tree | 13c95c72ccc8f8f21d0adb83c233ba1d28fbc3ae | |
parent | c8a837521b92082d47f986f61ec9ec0263146b7c (diff) | |
parent | acff2f2611e271b83c9190b060d42c88bb292fa5 (diff) |
Merge remote-tracking branch 'origin/5.12' into 5.13v5.13.0-rc3v5.13.0-rc2v5.13.0-rc1v5.13.0-beta4v5.13.05.13.0
Change-Id: Ice5a082f2a2a5e5341b8dbf0a2f0133ec8d303ca
-rw-r--r-- | src/mqtt/doc/qtmqtt.qdocconf | 1 | ||||
-rw-r--r-- | src/mqtt/qmqttconnection.cpp | 20 | ||||
-rw-r--r-- | tests/auto/qmqttclient/tst_qmqttclient.cpp | 5 |
3 files changed, 21 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 2ca1040..483e6f4 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) @@ -303,13 +304,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; } @@ -705,6 +706,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; } @@ -748,6 +753,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; diff --git a/tests/auto/qmqttclient/tst_qmqttclient.cpp b/tests/auto/qmqttclient/tst_qmqttclient.cpp index 8aec3d5..c4da40d 100644 --- a/tests/auto/qmqttclient/tst_qmqttclient.cpp +++ b/tests/auto/qmqttclient/tst_qmqttclient.cpp @@ -486,6 +486,8 @@ public slots: } else { response += char(0); // ackFlags response += char(0); // result + if (version == QMqttClient::MQTT_5_0) + response += char(0); // No properties } qDebug() << "Fake server response:" << connectionSuccess; socket->write(response); @@ -493,6 +495,7 @@ public slots: public: QTcpServer *server; QTcpSocket *socket; + QMqttClient::ProtocolVersion version{QMqttClient::MQTT_3_1_1}; bool connectionSuccess{false}; }; @@ -509,6 +512,8 @@ void Tst_QMqttClient::reconnect_QTBUG65726() client.setHostname(QLatin1String("localhost")); client.setPort(5726); + server.version = client.protocolVersion(); + client.connectToHost(); QTRY_COMPARE(client.state(), QMqttClient::Disconnected); QTRY_COMPARE(client.error(), QMqttClient::ProtocolViolation); |