Added check to prevent subscribe/unsubscribe to empty topics

This commit is contained in:
Andrei Balasescu 2020-04-12 01:20:08 +03:00
parent 7dd2ff90a9
commit 6099ee028f

View File

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