mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 11:03:05 +00:00
Merge branch 'fix_node_label_read_failure_issue' into 'main'
fix node label read failure issue See merge request app-frameworks/esp-matter!616
This commit is contained in:
@@ -1241,42 +1241,56 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
|
||||
break;
|
||||
|
||||
case ESP_MATTER_VAL_TYPE_CHAR_STRING:
|
||||
if (attribute_type) {
|
||||
*attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
|
||||
}
|
||||
if (attribute_size) {
|
||||
*attribute_size = val->val.a.t;
|
||||
}
|
||||
if (value) {
|
||||
int data_size_len = val->val.a.t - val->val.a.s;
|
||||
memcpy(value, (uint8_t *)&val->val.a.s, data_size_len);
|
||||
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
|
||||
{
|
||||
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
|
||||
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
|
||||
return ESP_FAIL;
|
||||
{
|
||||
if (attribute_type) {
|
||||
*attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
|
||||
}
|
||||
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
|
||||
size_t data_size_len = val->val.a.t - val->val.a.s;
|
||||
if (string_len >= UINT8_MAX || data_size_len != 1) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
uint8_t data_size = string_len;
|
||||
if (attribute_size) {
|
||||
*attribute_size = string_len + data_size_len;
|
||||
}
|
||||
if (value) {
|
||||
memcpy(value, (uint8_t *)&data_size, data_size_len);
|
||||
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
|
||||
{
|
||||
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
|
||||
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
|
||||
}
|
||||
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
|
||||
}
|
||||
break;
|
||||
|
||||
case ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING:
|
||||
if (attribute_type) {
|
||||
*attribute_type = ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE;
|
||||
}
|
||||
if (attribute_size) {
|
||||
*attribute_size = val->val.a.t;
|
||||
}
|
||||
if (value) {
|
||||
int data_size_len = val->val.a.t - val->val.a.s;
|
||||
memcpy(value, (uint8_t *)&val->val.a.s, data_size_len);
|
||||
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
|
||||
{
|
||||
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
|
||||
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
|
||||
return ESP_FAIL;
|
||||
{
|
||||
if (attribute_type) {
|
||||
*attribute_type = ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE;
|
||||
}
|
||||
size_t string_len = strnlen((const char *)val->val.a.b, val->val.a.s);
|
||||
size_t data_size_len = val->val.a.t - val->val.a.s;
|
||||
if (string_len >= UINT8_MAX || data_size_len != 2) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
uint16_t data_size = string_len;
|
||||
if (attribute_size) {
|
||||
*attribute_size = string_len + data_size_len;
|
||||
}
|
||||
if (value) {
|
||||
memcpy(value, (uint8_t *)&data_size, data_size_len);
|
||||
if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
|
||||
{
|
||||
ESP_LOGE(TAG, "Attribute buffer not enough, cannot copy the data to the attribute buffer."
|
||||
"Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
|
||||
}
|
||||
memcpy((value + data_size_len), (uint8_t *)val->val.a.b, (*attribute_size - data_size_len));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -613,6 +613,14 @@ esp_err_t enable(endpoint_t *endpoint)
|
||||
attribute::get_data_from_attr_val(&attribute->val, &matter_attributes[attribute_index].attributeType,
|
||||
&matter_attributes[attribute_index].size, NULL);
|
||||
|
||||
/* The length is not fixed for string attribute, so set it to the max size (32) to avoid overflow issue
|
||||
* when writing a longer string.
|
||||
*/
|
||||
if (attribute->val.type == ESP_MATTER_VAL_TYPE_CHAR_STRING ||
|
||||
attribute->val.type == ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING) {
|
||||
matter_attributes[attribute_index].size = attribute->val.val.a.s;
|
||||
}
|
||||
|
||||
matter_clusters[cluster_index].clusterSize += matter_attributes[attribute_index].size;
|
||||
attribute = attribute->next;
|
||||
attribute_index++;
|
||||
|
||||
Reference in New Issue
Block a user