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

1138 Commits

Author SHA1 Message Date
Topi Reinio
5238fdb1c3 Doc: Include namespaces in TOC
The QMqtt namespace was missing from the TOC as the .qhp subproject
selected only classes and headers.

Pick-to: 6.12
Change-Id: I5692ae2e77b80d9b3c4361945891e84c1ef4ccf7
Reviewed-by: Alexei Cazacov <alexei.cazacov@qt.io>
2026-10-25 15:09:56 +00:00
Tatiana Borisova
407ac111fd QMqttConnection: distinguish read errors from zero values
- The readBufferTyped<T>() method returns T{0} when it fails. But
in QtMqtt the value 0 is also used as "Success" return code.
In particular, src/mqtt/qmqttconnection.cpp
=> readBufferTyped<T>() returns 0 on failure, and finalize_connack()
reads the login result with it. src/mqtt/qmqttglobal.h =>
QMqtt::ReasonCode defines Success = 0.
So our failure value and the protocol's success value are the same
number.

- To fix this problem I make readBufferTyped<>() return std::nullopt
when the read fails, while using the returned value to represent
uccessfully read data. This allows callers to distinguish read errors
from valid zero values.

[ChangeLog][QMqttConnection][Important Behavior Changes] The Qt MQTT
client now stops parsing and closes the connection with the
ProtocolViolation error when a read error occurs while
parsing a packet.

Task-number: QTBUG-149867
Change-Id: I829a34cecfcb49ba330d5eb65aba755eee9326b0
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-10-23 10:09:58 +00:00
Qt Submodule Update Bot
d8fa0e633f Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I628aa6161920a7d3fa21db807f594e4d25b58f61
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-10-22 17:20:29 +00:00
Tatiana Borisova
51fe8b4f2e Limit MQTT packet size for MQTT 3.x connections
- Enforce the configured packet size limit locally for MQTT 3.1/3.1.1.
- Close the connection if the broker sends a packet exceeding the limit.

MQTT 3.1 and 3.1.1 have no way to tell the broker the maximum packet
size the client accepts, so the limit can only be applied on the
client side. This is helpful for clients on embedded devices, where
memory is limited and a very large packet from the broker could
exhaust it.

[ChangeLog][QMqttClient] The maximumPacketSize connection property is
now also enforced for MQTT 3.1 and 3.1.1 connections. Previously it was
only honored for MQTT 5.0. The client now closes the connection if the
broker sends a packet larger than this limit. This helps clients on
embedded devices to protect their limited memory. The default behavior
is unchanged: if no limit is set, only the protocol maximum of 256 MB
applies.

Change-Id: I26625325f490e2396fa493005c1f322253007a33
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-10-20 11:48:44 +00:00
Qt Submodule Update Bot
457877b453 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ifba06f310ebdadd2fd94311e0f2c2d5c4085cc9c
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-10-20 09:32:25 +00:00
Qt Submodule Update Bot
529a2ed7d9 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I7f1d48e7c4a059139d53409bd77f61a5e3e5392b
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-10-14 10:28:41 +00:00
Qt Submodule Update Bot
39f5d8bc63 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I4eda259e19bee548ad55c257ac4de89d6562e865
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-10-13 20:31:00 +00:00
Tatiana Borisova
a4ba93f3ca Add the readBufferSize property to limit the read buffer for clients
- this function should be used to protect your socket against receiving
too much data, which may eventually cause your application to run out
of memory.
- setSocketReadBufferSize(size) sets the size of internal read buffer
to be 'size' bytes.

[ChangeLog][QMqttClient] Added a readBufferSize property to limit
the transport buffer size.

Task-number: QTBUG-149866
Change-Id: I6ff843b66b50d019ecf620c25c47e0d779518113
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-10-09 15:34:07 +00:00
Tatiana Borisova
d24a6483d0 Document blocking I/O and threading considerations
- Document that disconnectFromHost() may block while waiting for pending
data to be written, with a timeout of up to 30 seconds.

- Recommend keeping QMqttClient and its transport outside the UI thread
because blocking I/O may occur and affect UI responsiveness.

Pick-to: 6.12
Task-number: QTBUG-150345
Change-Id: I27d300210750710c4a5138f8c3f97c7c929466af
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-10-08 09:42:57 +00:00
Qt Submodule Update Bot
e147dedea3 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I4d3b281b7ba556b9753806639db2b8f2a03db743
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-10-07 21:19:11 +00:00
Tatiana Borisova
1316c02fe7 MQTT 5: Add Maximum Packet Size check
Disconnect with reason code 0x95 (Packet too large) if a packet
exceeds the Maximum Packet Size limit, as required by section 3.1.2.11.4
of the MQTT 5 spec.

Note: This fix doesn't protect against memory exhaustion in user apps.
It just implements the spec requirement about message limit.

Pick-to: 6.12
Task-number: QTBUG-149866
Change-Id: I2baa8ceb95e4a045437e2caa51e5508b2fa8b2eb
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-10-06 13:05:52 +00:00
Qt Submodule Update Bot
ece01bf0ee Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Iad96afcd2d25ef4c6d1f0b085f782d1b81089ff3
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-09-30 21:41:02 +00:00
Qt Submodule Update Bot
24678da81e Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I0c6fb192baf73ae18b8ced356af0890d1d402c57
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-09-22 13:35:15 +00:00
Tatiana Borisova
21b866609f The Qt app can freeze forever if the broker sends a bad message
- When QMqttConnection reads a message, it keeps a count of the bytes
left to read -> by the dataSize argument. If a read fails, the count
is never reduced.
- The fix cleaning up the count of the bytes left to read, since
the reading is not working anymore and parsing should be stopped.
It allows to get read of potential freezes.

The patch also updates the QByteArray specialization to return a
default-constructed QBA in case of an error. This is more in line
with the default implementation.

Pick-to: 6.11 6.12 6.8
Task-number: QTBUG-149563
Change-Id: I8c8c5ef354103a996ac6e360fbc5c8f61d965f3d
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-09-15 09:06:31 +00:00
Qt Submodule Update Bot
6bdaef48c7 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I23dabe0789f9adc00ba3ab1e9af553c6e2eb3c67
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-09-14 22:30:33 +00:00
Qt Submodule Update Bot
c58aedad7a Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Id764db97c594b958cfc84a80ae85b6c5c0ad5574
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-09-10 00:05:42 +00:00
Qt Submodule Update Bot
dd767d7a57 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ic7d9314b90e2ff088c84f49acbc8a46f4258b1fb
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-09-02 05:07:22 +00:00
Tatiana Borisova
06d301aa50 Read the Remaining Length as a variable byte integer everywhere
- Every MQTT packet begins with a fixed header, whose second field is the
Remaining Length: the number of bytes that follow. It is not a byte. It
is spread over one to four bytes, seven value bits each, with the top
bit meaning "another byte follows". So values up to 127 take one byte,
and larger values take more.

Six packet types read it as a single quint8: SUBACK, UNSUBACK, PUBACK,
PUBREC, PUBREL and PUBCOMP. For most of them that used to be correct.
In MQTT 3.1.1 those packets contain nothing but a two byte identifier,
so the length was always exactly 2, which always fits in one byte. The
code did not even use the byte it read: it checked that the value was 2
and then hardcoded the length.

MQTT 5.0 support (ac66658) gave those packets an optional reason code
and properties, so the length can now be far above 127. That commit
switched off the "must be 2" check for MQTT 5.0 and began using the
byte as the real length, but kept reading only one byte. The check had
been the only thing making a one byte read safe, because a multi-byte
length always has its top bit set and so could never equal 2.

SUBACK never had a fixed length at all, since its payload carries one
reason code per subscribed topic filter. It has been misparsed for any
SUBACK above 127 bytes since the parser was written (d96011b).

Reading one byte of a two byte length consumes one byte too few, so the
remainder of the packet is then read as the next packet's header. The
client rejects a valid acknowledgement and stays out of step for the
rest of the connection. Brokers trigger this on ordinary traffic as
soon as they attach a reason string or user properties.

All six now use readVariableByteInteger(), and each rejects a length too
short to hold the fields the specification requires.

PUBREL also accepted a length of exactly 2 even for MQTT 5.0, which
rejected valid PUBREL packets carrying a reason code. It now accepts 2
or more there, and still requires exactly 2 for MQTT 3.1.1.

- Adds three regression tests driving the parser through the existing
FakeServer, so they need no broker.

Pick-to: 6.11 6.12 6.8
Task-number: QTBUG-149569
Change-Id: Ib239d836556e0cc14e13c116dee757fdd1a7ae81
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-09-01 17:40:37 +00:00
Tatiana Borisova
33538c5143 PINGRESP from the network should not push the counter below zero
- finalize_pingresp() lowers m_pingTimeout every time, with no lower
limit. A broker can send a pile of unasked-for replies to push the
counter deep below zero, and then the client can spend some unexpected
amount of time to reach back the number that means:
"the broker has stopped answering, drop the link.”
- The fix prohibits pushing the counter below zero.

Task-number: QTBUG-149662
Pick-to: 6.11 6.12 6.8
Change-Id: I7b25e8ac3f83fa262a19010df9a91b2ee1c006fd
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-09-01 14:32:40 +00:00
Tatiana Borisova
9e0428b917 Skip remaining data for messages with unknown requests
- finalize_suback() and finalize_unsuback() read the 2-byte request ID.
If no matching request was found, they returned immediately.
However, m_missingData remained non-zero.
The leftover bytes are then incorrectly interpreted as the header of
the next message!

- This change fixes the issue universally for all handlers in the
processDataHelper().

Pick-to: 6.11 6.12 6.8
Task-number: QTBUG-149570
Change-Id: I06c86414c3297caa386059a02fdec5c3765a0315
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-09-01 10:52:32 +00:00
Qt Submodule Update Bot
c7f7555d8e Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ic8fadb4442f209a70a15a076d56b166f4d122f75
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-09-01 00:54:22 +00:00
Tatiana Borisova
011eb1e424 Fix topic alias bounds and storage sizes
- In the f8ecf4d56a we found that the
m_receiveAliases bounds check used a wrong property:
m_clientPrivate->m_serverConnectionProperties.maximumTopicAlias(),
but it must use instead:
m_clientPrivate->m_connectionProperties.maximumTopicAlias().

So, the idea is m_receiveAliases is sized according to the maximum
topic alias value declared by the client in CONNECT, while
m_publishAliases is sized according to the maximum value declared
by the server in CONNACK.

The previous fix did not update all related code.
1) The resize() calls for m_receiveAliases and m_publishAliases
still used the wrong properties.
2) The bounds check for m_publishAliases still used the client's
maximumTopicAlias() value instead of the server's.

- Update the resize() calls to use the appropriate connection
properties and fix the bounds check for m_publishAliases.

Amends f8ecf4d56a

Pick-to: 6.11 6.12 6.8
Task-number: QTBUG-149564
Change-Id: I252c67966bf28c6994f34b19024d1b7894748473
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-08-28 17:36:29 +00:00
Qt Submodule Update Bot
ee16836877 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I13a69da7a50229cdfc602dda0edac4f2645da59e
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-08-28 16:01:26 +00:00
Tatiana Borisova
c94175ff43 Stop parsing after closeConnection()
- Parsing continued after closeConnection(), leaving the client in the
"connected" state with a dead socket. This led to a permanent,
unrecoverable wedge in Release builds and a crash in Debug builds.

- Check whether the client is already disconnected before changing its
state to BrokerConnected.

Pick-to: 6.11 6.12 6.8
Task-number: QTBUG-149565
Change-Id: I13d45c24d24fe862d9aec6a7e421f5ef4d494db0
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-08-28 12:07:32 +00:00
Tatiana Borisova
13288574c1 Check readVariableByteInteger() return value
- On error, readVariableByteInteger() closes the connection and
returns-1. In this case, message handling should stop.

- Add checks for the return value to stop processing when -1 is returned.

Pick-to: 6.11 6.8 6.12
Task-number: QTBUG-149565
Change-Id: I8f6cc8d6f3011a89d3bd4033a3432f383e1e9164
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-08-28 12:07:30 +00:00
Tatiana Borisova
ecaf42152e Number overflow while rejecting a too-long length
- The length reader checked its 4-byte limit after doing the maths.
So, a 5th byte was multiplied in and overflows before the value
was thrown away. But it was not noticed, because we thrown it away
and returned -1.

- The fix moves iteration++ and if (iteration > 4) before the
calculation, preventing the overflow.

Pick-to: 6.11 6.8 6.12
Task-number: QTBUG-149571
Change-Id: I78c2063c7e01af3e8f196f824216d31de92fab48
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-08-28 12:07:28 +00:00
Qt Submodule Update Bot
ba2b82223a Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ie3ba332b167426218e86a904bc99a0bed0e4556c
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-08-26 06:34:34 +00:00
Qt Submodule Update Bot
90f2efdd5d Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I45f8e4efaf7d02f0ef886257dd1ccaa1ad4f457e
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-08-22 02:39:59 +00:00
Qt Submodule Update Bot
b73e4d4ffc Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I2751f6696663e560d274e1df7889943a578a6914
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-08-18 00:22:08 +00:00
Tatiana Borisova
96d602b65f Update to coin_module_test_template_v3.yaml
- The main differences between v2 and v3 are:
  * `coin_module_test_template_v2.yaml` ignores autotest return
    codes because the `COIN_CTEST_IGNORE_EXIT_CODE` flag is set.
  * The Axivion build was moved from coin_module_build_template_v2.yaml
    to coin_module_test_template_v3.yaml in commit
    c3ddec2f15a1cf806d8df444952cb2c2231ae4ad
- Switch the qtmqtt submodule to the newer v3 version to improve
the submodule CI experience for autotests and restore Axivion
checks.

Pick-to: 6.12 6.11
Change-Id: I1695c8ca1af616512dff437a0a4cdbd0491412d4
Reviewed-by: Toni Saario <toni.saario@qt.io>
2026-08-17 09:51:21 +00:00
Qt Submodule Update Bot
fe85eff00c Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I49e7ca4073c1c483370a22ff51d8cde8d63345f4
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-08-14 10:49:39 +00:00
Qt Submodule Update Bot
16862e4fa7 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I5706ec8cff106f1a19fcf9652ba06ae7a3076bab
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-08-04 15:26:25 +00:00
Qt Submodule Update Bot
2caa279c61 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I8126f0e67a0c58f8f671890050d3c13bf6e8e8d8
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-07-29 15:25:41 +00:00
Jani Heikkinen
ebd3d87293 Replace Q_ENUMS with Q_ENUM
Amends ea3dc64d3f,
7467bbdc84, and
ea0d792a44 (all before 6.0).

Fixes: QTBUG-148625
Pick-to: 6.12 6.11 6.8
Change-Id: I2f9b24f7e32d437cce258dfdce0d669c8d2638e1
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2026-07-29 11:40:44 +00:00
Tatiana Borisova
14de26f60b Fix Qt-RangeLoopDetach Axivion warnings
- use std::as_const() where possible, and introduce an intermediate
  local const variable where it is not.

Axivion-Id: qt_Add-ons_qtmqtt_dev_linux:SV34
Axivion-Id: qt_Add-ons_qtmqtt_dev_linux:SV35
Axivion-Id: qt_Add-ons_qtmqtt_dev_linux:SV36
Axivion-Id: qt_Add-ons_qtmqtt_dev_linux:SV37
Pick-to: 6.12
Task-number: QTBUG-144762
Change-Id: I7b6d53116269007aca7d6f050b2abeb2515e9390
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-07-22 10:41:05 +00:00
Qt Submodule Update Bot
a85b5c3ecf Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I63842312d21575b3cb7f0722446ec14149aa2a5e
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-07-18 21:34:00 +00:00
Qt Submodule Update Bot
2dc7e69f0e Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I23bbd285e1aa00624ee2e21a65b54ec3693d416f
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-07-15 00:24:21 +00:00
Qt Submodule Update Bot
9cc2b3859d Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I8d5b1115587cdc9e4625785a23acba9cd770936a
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-07-09 20:08:18 +00:00
Qt Submodule Update Bot
088b583810 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I92ec408cffa255a953e07fe93761fe9bf5fcc27b
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-07-07 15:18:07 +00:00
Qt Submodule Update Bot
fa9b04ab15 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I2828b08e810e9fd3de8b3536472d21c17c67bf9f
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-07-01 17:52:59 +00:00
Qt Submodule Update Bot
53aba306b9 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I7f19ead9837dcb5a80b0fabae0f3e2aae1562752
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-06-25 07:49:14 +00:00
Qt Submodule Update Bot
3b476b23eb Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ie71907f1afdf7b36ba1a363db0855716b731d96a
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-06-18 21:00:58 +00:00
Qt Submodule Update Bot
cf66710eb6 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ibbf482f41eb56bea86a418094a81516fa913ae07
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-06-04 21:59:53 +00:00
Jani Heikkinen
5d592b2aa3 Bump version to 6.13.0
Change-Id: I63790a12e9734c478bb9f0bb86ff4527cd69b9e1
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-06-04 21:59:51 +00:00
Qt Submodule Update Bot
ae08a87fc4 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: If9e34b78b899338e3bf3587caea8f5ef929fa39e
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-06-03 01:35:30 +00:00
Qt Submodule Update Bot
1d7f954339 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I6b6c3fe3edd69ee2444bc7246d1c6916e3f8ba5d
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-06-02 05:06:50 +00:00
Qt Submodule Update Bot
f7267c6452 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ieff8861b81fe08d9e05eae5343ad6716d7698383
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-05-31 15:44:17 +00:00
Qt Submodule Update Bot
cefbe34e78 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: Ieb10ad55da60b7ef62c9d84479fe98f5ea515209
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-05-29 01:11:37 +00:00
Qt Submodule Update Bot
b7d124d65f Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I858f5ccddc5f368659f43646fa005537dce71a87
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-05-25 20:20:43 +00:00
Qt Submodule Update Bot
e7616f09c1 Update dependencies on 'dev' in qt/qtmqtt
Change-Id: I77d9159d75ac22b8fff8996dc4e403bc42421563
Reviewed-by: Qt Submodule Update Bot <qt_submodule_update_bot@qt-project.org>
2026-05-22 12:04:27 +00:00