Added check to prevent subscribe/unsubscribe to empty topics
This commit is contained in:
parent
7dd2ff90a9
commit
6099ee028f
@ -548,10 +548,14 @@ boolean PubSubClient::subscribe(const char* topic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
|
boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
|
||||||
|
size_t topicLength = strlen(topic);
|
||||||
|
if (topic == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (qos > 1) {
|
if (qos > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
|
if (MQTT_MAX_PACKET_SIZE < 9 + topicLength) {
|
||||||
// Too long
|
// Too long
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -572,7 +576,11 @@ boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean PubSubClient::unsubscribe(const char* topic) {
|
boolean PubSubClient::unsubscribe(const char* topic) {
|
||||||
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
|
size_t topicLength = strlen(topic);
|
||||||
|
if (topic == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (MQTT_MAX_PACKET_SIZE < 9 + topicLength) {
|
||||||
// Too long
|
// Too long
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user