fix crash on empty mqtt-payload

This commit is contained in:
MichaelDvP
2021-11-08 18:30:33 +01:00
parent a3022f6f20
commit b1f72b0e3e

View File

@@ -225,8 +225,10 @@ void Mqtt::incoming(const char * topic, const char * payload) {
void Mqtt::on_message(const char * topic, const char * payload, size_t len) { void Mqtt::on_message(const char * topic, const char * payload, size_t len) {
// sometimes the payload is not terminated correctly, so make a copy // sometimes the payload is not terminated correctly, so make a copy
// convert payload to a null-terminated char string // convert payload to a null-terminated char string
char message[len + 2]; char message[len + 2] = {'\0'};
strlcpy(message, payload, len + 1); if (payload != nullptr) {
strlcpy(message, payload, len + 1);
}
#if defined(EMSESP_DEBUG) #if defined(EMSESP_DEBUG)
if (len) { if (len) {