diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2020-05-07 04:05:51 +0300 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2020-05-15 19:38:14 +0300 |
commit | de07f41c7b1c3ffaac7ca8b513ee8cc56883983a (patch) | |
tree | eaec61dccdc8d382888287c23bcfb59a671289e1 | |
parent | fc130f36812073be7243e969a2748d27ac47ee8d (diff) |
QMqttConnection::sendControlSubscribe: minor simplification
plus add some more verbosity on invalid argument values
Change-Id: I7e0a091c2603e16d3e1d90f116e3f134122d42a2
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r-- | src/mqtt/qmqttconnection.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp index d55b0cd..9c3c7d6 100644 --- a/src/mqtt/qmqttconnection.cpp +++ b/src/mqtt/qmqttconnection.cpp @@ -466,6 +466,17 @@ QMqttSubscription *QMqttConnection::sendControlSubscribe(const QMqttTopicFilter { qCDebug(lcMqttConnection) << Q_FUNC_INFO << " Topic:" << topic << " qos:" << qos; + // Overflow protection + if (Q_UNLIKELY(!topic.isValid())) { + qCWarning(lcMqttConnection) << "Invalid subscription topic filter."; + return nullptr; + } + + if (Q_UNLIKELY(qos > 2)) { + qCWarning(lcMqttConnection) << "Invalid subscription QoS."; + return nullptr; + } + if (m_clientPrivate->m_protocolVersion == QMqttClient::MQTT_5_0) { const QString sharedSubscriptionName = topic.sharedSubscriptionName(); if (!sharedSubscriptionName.isEmpty()) { @@ -497,20 +508,8 @@ QMqttSubscription *QMqttConnection::sendControlSubscribe(const QMqttTopicFilter if (m_clientPrivate->m_protocolVersion == QMqttClient::MQTT_5_0) packet.appendRaw(writeSubscriptionProperties(properties)); - // Overflow protection - if (!topic.isValid()) { - qCDebug(lcMqttConnection) << "Invalid subscription topic filter."; - return nullptr; - } - packet.append(topic.filter().toUtf8()); - - switch (qos) { - case 0: packet.append(char(0x0)); break; - case 1: packet.append(char(0x1)); break; - case 2: packet.append(char(0x2)); break; - default: return nullptr; - } + packet.append(char(qos)); auto result = new QMqttSubscription(this); result->setTopic(topic); |