@@ -45,42 +45,44 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler
45
45
// / @brief From command AddScene, allows handler to filter through clusters in command to serialize only the supported ones.
46
46
// / @param endpoint[in] Endpoint ID
47
47
// / @param extensionFieldSet[in] ExtensionFieldSets provided by the AddScene Command, pre initialized
48
- // / @param cluster[out] Cluster in the Extension field set, filled by the function
49
48
// / @param serialisedBytes[out] Buffer to fill from the ExtensionFieldSet in command
50
49
// / @return CHIP_NO_ERROR if successful, CHIP_ERROR_INVALID_ARGUMENT if the cluster is not supported, CHIP_ERROR value otherwise
51
50
virtual CHIP_ERROR SerializeAdd (EndpointId endpoint,
52
51
const app::Clusters::Scenes::Structs::ExtensionFieldSet::DecodableType & extensionFieldSet,
53
- ClusterId & cluster, MutableByteSpan & serializedBytes) override
52
+ MutableByteSpan & serializedBytes) override
54
53
{
55
54
app::Clusters::Scenes::Structs::AttributeValuePair::DecodableType aVPair;
56
55
TLV::TLVWriter writer;
57
56
TLV::TLVType outer;
57
+ size_t pairTotal = 0 ;
58
+ uint8_t pairCount = 0 ;
58
59
59
- uint8_t pairCount = 0 ;
60
- uint8_t valueBytes = 0 ;
61
-
62
- VerifyOrReturnError (SupportsCluster (endpoint, extensionFieldSet.clusterID ), CHIP_ERROR_INVALID_ARGUMENT);
63
-
64
- cluster = extensionFieldSet.clusterID ;
60
+ // Verify size of list
61
+ extensionFieldSet.attributeValueList .ComputeSize (&pairTotal);
62
+ VerifyOrReturnError (pairTotal <= kMaxAvPair , CHIP_ERROR_BUFFER_TOO_SMALL);
65
63
66
64
auto pair_iterator = extensionFieldSet.attributeValueList .begin ();
67
65
while (pair_iterator.Next () && pairCount < kMaxAvPair )
68
66
{
69
67
aVPair = pair_iterator.GetValue ();
70
68
mAVPairs [pairCount].attributeID = aVPair.attributeID ;
71
- auto value_iterator = aVPair.attributeValue .begin ();
69
+ size_t valueBytesTotal = 0 ;
70
+ uint8_t valueBytesCount = 0 ;
72
71
73
- valueBytes = 0 ;
74
- while (value_iterator.Next () && valueBytes < kMaxValueSize )
72
+ aVPair.attributeValue .ComputeSize (&valueBytesTotal);
73
+ VerifyOrReturnError (valueBytesTotal <= kMaxValueSize , CHIP_ERROR_BUFFER_TOO_SMALL);
74
+
75
+ auto value_iterator = aVPair.attributeValue .begin ();
76
+ while (value_iterator.Next ())
75
77
{
76
- mValueBuffer [pairCount][valueBytes ] = value_iterator.GetValue ();
77
- valueBytes ++;
78
+ mValueBuffer [pairCount][valueBytesCount ] = value_iterator.GetValue ();
79
+ valueBytesCount ++;
78
80
}
79
81
// Check we could go through all bytes of the value
80
82
ReturnErrorOnFailure (value_iterator.GetStatus ());
81
83
82
84
mAVPairs [pairCount].attributeValue = mValueBuffer [pairCount];
83
- mAVPairs [pairCount].attributeValue .reduce_size (valueBytes );
85
+ mAVPairs [pairCount].attributeValue .reduce_size (valueBytesCount );
84
86
pairCount++;
85
87
}
86
88
// Check we could go through all pairs in incomming command
@@ -90,7 +92,7 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler
90
92
attributeValueList = mAVPairs ;
91
93
attributeValueList.reduce_size (pairCount);
92
94
93
- writer.Init (serialisedBytes );
95
+ writer.Init (serializedBytes );
94
96
ReturnErrorOnFailure (writer.StartContainer (TLV::AnonymousTag (), TLV::kTLVType_Structure , outer));
95
97
ReturnErrorOnFailure (app::DataModel::Encode (
96
98
writer, TLV::ContextTag (app::Clusters::Scenes::Structs::ExtensionFieldSet::Fields::kAttributeValueList ),
@@ -114,38 +116,44 @@ class DefaultSceneHandlerImpl : public scenes::SceneHandler
114
116
115
117
TLV::TLVReader reader;
116
118
TLV::TLVType outer;
117
- uint8_t pairCount = 0 ;
118
- uint8_t valueBytes = 0 ;
119
-
120
- VerifyOrReturnError (SupportsCluster (endpoint, cluster), CHIP_ERROR_INVALID_ARGUMENT);
119
+ size_t pairTotal = 0 ;
120
+ uint8_t pairCount = 0 ;
121
121
122
122
extensionFieldSet.clusterID = cluster;
123
123
reader.Init (serialisedBytes);
124
124
ReturnErrorOnFailure (reader.Next (TLV::kTLVType_Structure , TLV::AnonymousTag ()));
125
125
ReturnErrorOnFailure (reader.EnterContainer (outer));
126
126
ReturnErrorOnFailure (reader.Next (
127
- TLV::kTLVType_Array ,
128
- TLV::ContextTag (app::Clusters::Scenes::Structs::ExtensionFieldSet::Fields::kAttributeValueList )));
127
+ TLV::kTLVType_Array , TLV::ContextTag (app::Clusters::Scenes::Structs::ExtensionFieldSet::Fields::kAttributeValueList )));
129
128
attributeValueList.Decode (reader);
130
129
130
+ // Verify size of list
131
+ attributeValueList.ComputeSize (&pairTotal);
132
+ VerifyOrReturnError (pairTotal <= kMaxAvPair , CHIP_ERROR_BUFFER_TOO_SMALL);
133
+
131
134
auto pair_iterator = attributeValueList.begin ();
132
- while (pair_iterator.Next () && pairCount < kMaxAvPair )
135
+ while (pair_iterator.Next ())
133
136
{
134
137
decodePair = pair_iterator.GetValue ();
135
138
mAVPairs [pairCount].attributeID = decodePair.attributeID ;
136
- auto value_iterator = decodePair.attributeValue .begin ();
137
- valueBytes = 0 ;
139
+ size_t valueBytesTotal = 0 ;
140
+ uint8_t valueBytesCount = 0 ;
141
+
142
+ // Verify size of attribute value
143
+ decodePair.attributeValue .ComputeSize (&valueBytesTotal);
144
+ VerifyOrReturnError (valueBytesTotal <= kMaxValueSize , CHIP_ERROR_BUFFER_TOO_SMALL);
138
145
139
- while (value_iterator.Next () && valueBytes < kMaxValueSize )
146
+ auto value_iterator = decodePair.attributeValue .begin ();
147
+ while (value_iterator.Next () && valueBytesCount < kMaxValueSize )
140
148
{
141
- mValueBuffer [pairCount][valueBytes ] = value_iterator.GetValue ();
142
- valueBytes ++;
149
+ mValueBuffer [pairCount][valueBytesCount ] = value_iterator.GetValue ();
150
+ valueBytesCount ++;
143
151
}
144
152
// Check we could go through all bytes of the value
145
153
ReturnErrorOnFailure (value_iterator.GetStatus ());
146
154
147
155
mAVPairs [pairCount].attributeValue = mValueBuffer [pairCount];
148
- mAVPairs [pairCount].attributeValue .reduce_size (valueBytes );
156
+ mAVPairs [pairCount].attributeValue .reduce_size (valueBytesCount );
149
157
pairCount++;
150
158
};
151
159
// Check we could go through all pairs stored in memory
0 commit comments