@@ -1239,42 +1239,56 @@ esp_err_t get_data_from_attr_val(esp_matter_attr_val_t *val, EmberAfAttributeTyp
1239
1239
break ;
1240
1240
1241
1241
case ESP_MATTER_VAL_TYPE_CHAR_STRING:
1242
- if (attribute_type) {
1243
- *attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
1244
- }
1245
- if (attribute_size) {
1246
- *attribute_size = val->val .a .t ;
1247
- }
1248
- if (value) {
1249
- int data_size_len = val->val .a .t - val->val .a .s ;
1250
- memcpy (value, (uint8_t *)&val->val .a .s , data_size_len);
1251
- if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
1252
- {
1253
- ESP_LOGE (TAG, " Attribute buffer not enough, cannot copy the data to the attribute buffer."
1254
- " Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST" );
1255
- return ESP_FAIL;
1242
+ {
1243
+ if (attribute_type) {
1244
+ *attribute_type = ZCL_CHAR_STRING_ATTRIBUTE_TYPE;
1245
+ }
1246
+ size_t string_len = strnlen ((const char *)val->val .a .b , val->val .a .s );
1247
+ size_t data_size_len = val->val .a .t - val->val .a .s ;
1248
+ if (string_len >= UINT8_MAX || data_size_len != 1 ) {
1249
+ return ESP_ERR_INVALID_ARG;
1250
+ }
1251
+ uint8_t data_size = string_len;
1252
+ if (attribute_size) {
1253
+ *attribute_size = string_len + data_size_len;
1254
+ }
1255
+ if (value) {
1256
+ memcpy (value, (uint8_t *)&data_size, data_size_len);
1257
+ if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
1258
+ {
1259
+ ESP_LOGE (TAG, " Attribute buffer not enough, cannot copy the data to the attribute buffer."
1260
+ " Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST" );
1261
+ return ESP_FAIL;
1262
+ }
1263
+ memcpy ((value + data_size_len), (uint8_t *)val->val .a .b , (*attribute_size - data_size_len));
1256
1264
}
1257
- memcpy ((value + data_size_len), (uint8_t *)val->val .a .b , (*attribute_size - data_size_len));
1258
1265
}
1259
1266
break ;
1260
1267
1261
1268
case ESP_MATTER_VAL_TYPE_LONG_CHAR_STRING:
1262
- if (attribute_type) {
1263
- *attribute_type = ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE;
1264
- }
1265
- if (attribute_size) {
1266
- *attribute_size = val->val .a .t ;
1267
- }
1268
- if (value) {
1269
- int data_size_len = val->val .a .t - val->val .a .s ;
1270
- memcpy (value, (uint8_t *)&val->val .a .s , data_size_len);
1271
- if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
1272
- {
1273
- ESP_LOGE (TAG, " Attribute buffer not enough, cannot copy the data to the attribute buffer."
1274
- " Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST" );
1275
- return ESP_FAIL;
1269
+ {
1270
+ if (attribute_type) {
1271
+ *attribute_type = ZCL_LONG_CHAR_STRING_ATTRIBUTE_TYPE;
1272
+ }
1273
+ size_t string_len = strnlen ((const char *)val->val .a .b , val->val .a .s );
1274
+ size_t data_size_len = val->val .a .t - val->val .a .s ;
1275
+ if (string_len >= UINT8_MAX || data_size_len != 2 ) {
1276
+ return ESP_ERR_INVALID_ARG;
1277
+ }
1278
+ uint16_t data_size = string_len;
1279
+ if (attribute_size) {
1280
+ *attribute_size = string_len + data_size_len;
1281
+ }
1282
+ if (value) {
1283
+ memcpy (value, (uint8_t *)&data_size, data_size_len);
1284
+ if (*attribute_size > CONFIG_ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST)
1285
+ {
1286
+ ESP_LOGE (TAG, " Attribute buffer not enough, cannot copy the data to the attribute buffer."
1287
+ " Please configure the buffer size through menuconfig ESP_MATTER_ATTRIBUTE_BUFFER_LARGEST" );
1288
+ return ESP_FAIL;
1289
+ }
1290
+ memcpy ((value + data_size_len), (uint8_t *)val->val .a .b , (*attribute_size - data_size_len));
1276
1291
}
1277
- memcpy ((value + data_size_len), (uint8_t *)val->val .a .b , (*attribute_size - data_size_len));
1278
1292
}
1279
1293
break ;
1280
1294
0 commit comments