|
33 | 33 | #include <lib/support/logging/CHIPLogging.h>
|
34 | 34 | #include <platform/LockTracker.h>
|
35 | 35 | #include <protocols/interaction_model/StatusCode.h>
|
| 36 | +#include <app/util/ember-io-storage.h> |
36 | 37 |
|
37 | 38 | using chip::Protocols::InteractionModel::Status;
|
38 | 39 |
|
@@ -291,6 +292,27 @@ CHIP_ERROR emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const EmberA
|
291 | 292 | }
|
292 | 293 | }
|
293 | 294 |
|
| 295 | + for (uint8_t i = 0; ep && (i < ep->clusterCount); i++) { |
| 296 | + if (!ep->cluster) { |
| 297 | + continue; |
| 298 | + } |
| 299 | + |
| 300 | + const EmberAfCluster * cluster = &(ep->cluster[i]); |
| 301 | + if (!cluster->attributes) { |
| 302 | + continue; |
| 303 | + } |
| 304 | + |
| 305 | + for (uint16_t j = 0; j < cluster->attributeCount; j++) { |
| 306 | + const EmberAfAttributeMetadata * attr = &(cluster->attributes[j]); |
| 307 | + if (emberAfAttributeSize(attr) > gEmberAttributeIOBufferSpan.size()) { |
| 308 | + ChipLogError( |
| 309 | + DataManagement, |
| 310 | + "Attribute %u (id=" ChipLogFormatMEI ") of Cluster %u (id=" ChipLogFormatMEI ") too large", |
| 311 | + j, ChipLogValueMEI(attr->attributeId), i, ChipLogValueMEI(cluster->clusterId)); |
| 312 | + return CHIP_ERROR_NO_MEMORY; |
| 313 | + } |
| 314 | + } |
| 315 | + } |
294 | 316 | emAfEndpoints[index].endpoint = id;
|
295 | 317 | emAfEndpoints[index].deviceTypeList = deviceTypeList;
|
296 | 318 | emAfEndpoints[index].endpointType = ep;
|
@@ -639,10 +661,18 @@ Status emAfReadOrWriteAttribute(const EmberAfAttributeSearchRecord * attRecord,
|
639 | 661 | // Is the attribute externally stored?
|
640 | 662 | if (am->mask & ATTRIBUTE_MASK_EXTERNAL_STORAGE)
|
641 | 663 | {
|
642 |
| - return (write ? emberAfExternalAttributeWriteCallback(attRecord->endpoint, attRecord->clusterId, |
643 |
| - am, buffer) |
644 |
| - : emberAfExternalAttributeReadCallback(attRecord->endpoint, attRecord->clusterId, |
645 |
| - am, buffer, emberAfAttributeSize(am))); |
| 664 | + if (write) { |
| 665 | + return emberAfExternalAttributeWriteCallback(attRecord->endpoint, attRecord->clusterId, |
| 666 | + am, buffer); |
| 667 | + } |
| 668 | + |
| 669 | + if (readLength < emberAfAttributeSize(am)) { |
| 670 | + // Prevent a potential buffer overflow |
| 671 | + return Status::ResourceExhausted; |
| 672 | + } |
| 673 | + |
| 674 | + return emberAfExternalAttributeReadCallback(attRecord->endpoint, attRecord->clusterId, |
| 675 | + am, buffer, emberAfAttributeSize(am)); |
646 | 676 | }
|
647 | 677 |
|
648 | 678 | // Internal storage is only supported for fixed endpoints
|
|
0 commit comments