From a5bdebab54d35355b9d2a7e4cc58b6de72845a70 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Thu, 23 Nov 2023 18:32:35 +0800 Subject: [PATCH] attribute_override: Add attribute type restriction for attribute_override callback --- components/esp_matter/esp_matter_core.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index 2041ed3f1..f0ea68057 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -1353,6 +1353,17 @@ esp_err_t set_override_callback(attribute_t *attribute, callback_t callback) return ESP_ERR_INVALID_ARG; } _attribute_t *current_attribute = (_attribute_t *)attribute; + if (current_attribute->val.type == ESP_MATTER_VAL_TYPE_ARRAY || + current_attribute->val.type == ESP_MATTER_VAL_TYPE_OCTET_STRING || + current_attribute->val.type == ESP_MATTER_VAL_TYPE_CHAR_STRING || + current_attribute->val.type == ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING || + current_attribute->val.type == ESP_MATTER_VAL_TYPE_LONG_OCTET_STRING) { + // The override callback might allocate memory and we have no way to free the memory + // TODO: Add memory-safe override callback for these attribute types + ESP_LOGE(TAG, "Cannot set override callback for attribute 0x%" PRIX32 " on cluster 0x%" PRIX32, + current_attribute->attribute_id, current_attribute->cluster_id); + return ESP_ERR_NOT_SUPPORTED; + } current_attribute->override_callback = callback; current_attribute->flags |= ATTRIBUTE_FLAG_OVERRIDE; return ESP_OK;