Allow zero-length 'last-will' messages

This commit is contained in:
Sergio R. Caprile 2024-04-11 11:20:46 -03:00
parent 3c3c775213
commit 2ac3552e6e
2 changed files with 2 additions and 2 deletions

View File

@ -4333,7 +4333,7 @@ void mg_mqtt_login(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
total_len += 2 + (uint32_t) opts->pass.len;
hdr[7] |= MQTT_HAS_PASSWORD;
}
if (opts->topic.len > 0 && opts->message.len > 0) {
if (opts->topic.len > 0) { // allow zero-length msgs, message.len is size_t
total_len += 4 + (uint32_t) opts->topic.len + (uint32_t) opts->message.len;
hdr[7] |= MQTT_HAS_WILL;
}

View File

@ -277,7 +277,7 @@ void mg_mqtt_login(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
total_len += 2 + (uint32_t) opts->pass.len;
hdr[7] |= MQTT_HAS_PASSWORD;
}
if (opts->topic.len > 0 && opts->message.len > 0) {
if (opts->topic.len > 0) { // allow zero-length msgs, message.len is size_t
total_len += 4 + (uint32_t) opts->topic.len + (uint32_t) opts->message.len;
hdr[7] |= MQTT_HAS_WILL;
}