1
0
mirror of https://github.com/qt/qtmqtt.git synced 2026-10-25 16:16:26 +00:00

Merge remote-tracking branch 'origin/5.12' into 5.13

Change-Id: Ice5a082f2a2a5e5341b8dbf0a2f0133ec8d303ca
This commit is contained in:
Qt Forward Merge Bot 2019-04-20 03:00:22 +02:00
commit 72257654cc
3 changed files with 21 additions and 5 deletions

View File

@ -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"

View File

@ -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;

View File

@ -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);