Merge pull request #727 from sn0kerbuzz/fix-subscribe-empty-topic

Added check to prevent subscribe/unsubscribe to empty topics
This commit is contained in:
Nick O'Leary 2020-05-09 22:19:35 +01:00 committed by GitHub
commit 25977bef8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -548,10 +548,14 @@ boolean PubSubClient::subscribe(const char* topic) {
}
boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
size_t topicLength = strlen(topic);
if (topic == 0) {
return false;
}
if (qos > 1) {
return false;
}
if (MQTT_MAX_PACKET_SIZE < 9 + strlen(topic)) {
if (MQTT_MAX_PACKET_SIZE < 9 + topicLength) {
// Too long
return false;
}
@ -572,7 +576,11 @@ boolean PubSubClient::subscribe(const char* topic, uint8_t qos) {
}
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
return false;
}