From b438a9e1e4c7d88bbc022ea6e08bcd6d47b4b09b Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Fri, 20 Mar 2020 10:33:40 +0100 Subject: [PATCH] Fix potential crash. getZigbeeStatusMessage() does not return null anymore but empty string if the code is not found. --- tasmota/xdrv_23_zigbee_0_constants.ino | 2 +- tasmota/xdrv_23_zigbee_5_converters.ino | 5 +---- tasmota/xdrv_23_zigbee_8_parsers.ino | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tasmota/xdrv_23_zigbee_0_constants.ino b/tasmota/xdrv_23_zigbee_0_constants.ino index 63d851c04..d97a26f9f 100644 --- a/tasmota/xdrv_23_zigbee_0_constants.ino +++ b/tasmota/xdrv_23_zigbee_0_constants.ino @@ -474,7 +474,7 @@ const __FlashStringHelper* getZigbeeStatusMessage(uint8_t status) { return (const __FlashStringHelper*) statl->status_msg; } } - return nullptr; + return F(""); } #endif // USE_ZIGBEE diff --git a/tasmota/xdrv_23_zigbee_5_converters.ino b/tasmota/xdrv_23_zigbee_5_converters.ino index 12bb658ec..dfe544cbd 100644 --- a/tasmota/xdrv_23_zigbee_5_converters.ino +++ b/tasmota/xdrv_23_zigbee_5_converters.ino @@ -506,10 +506,7 @@ void ZCLFrame::parseResponse(void) { // "Status" json[F(D_JSON_ZIGBEE_STATUS)] = status; // "StatusMessage" - const __FlashStringHelper* statm = getZigbeeStatusMessage(status); - if (statm) { - json[F(D_JSON_ZIGBEE_STATUS_MSG)] = statm; - } + json[F(D_JSON_ZIGBEE_STATUS_MSG)] = getZigbeeStatusMessage(status); // Add Endpoint json[F(D_CMND_ZIGBEE_ENDPOINT)] = _srcendpoint; // Add Group if non-zero diff --git a/tasmota/xdrv_23_zigbee_8_parsers.ino b/tasmota/xdrv_23_zigbee_8_parsers.ino index fa73c3797..e9c4b6368 100644 --- a/tasmota/xdrv_23_zigbee_8_parsers.ino +++ b/tasmota/xdrv_23_zigbee_8_parsers.ino @@ -347,9 +347,7 @@ int32_t Z_DataConfirm(int32_t res, const class SBuffer &buf) { char status_message[32]; if (status) { // only report errors - const char * statm = (const char*) getZigbeeStatusMessage(status); - if (nullptr == statm) { statm = PSTR(""); } - strncpy_P(status_message, statm, sizeof(status_message)); + strncpy_P(status_message, (const char*) getZigbeeStatusMessage(status), sizeof(status_message)); status_message[sizeof(status_message)-1] = 0; // truncate if needed, strlcpy is safer but strlcpy_P does not exist Response_P(PSTR("{\"" D_JSON_ZIGBEE_CONFIRM "\":{\"" D_CMND_ZIGBEE_ENDPOINT "\":%d"