@@ -214,29 +214,40 @@ void ArduinoCloudThing::decode(uint8_t *payload, size_t length) {
214
214
// parse cbor object
215
215
cbor_value_enter_container (&dataArray, &recursedMap);
216
216
217
- CborType type = cbor_value_get_type (&recursedMap);
218
- if (type != CborMapType) {
217
+ if (cbor_value_get_type (&recursedMap) != CborMapType) {
219
218
// stop the decode when 1st item thai is not a cbor map is found.
220
- cbor_value_advance (&dataArray);
219
+ err = cbor_value_advance (&dataArray);
220
+ // avoid infinite loop if it is not possible to advance to the next array value
221
+ if (err != CborNoError) {
222
+ break ;
223
+ }
224
+ // go to the next element
221
225
continue ;
222
226
223
227
} else {
224
-
225
228
while (!cbor_value_at_end (&recursedMap)) {
226
229
227
230
// if the current element is not a cbor object as expected, skip it and go ahead.
228
231
if (cbor_value_get_type (&recursedMap) != CborMapType) {
229
- cbor_value_advance (&recursedMap);
232
+
233
+ err = cbor_value_advance (&recursedMap);
234
+ if (err != CborNoError) {
235
+ break ;
236
+ }
230
237
continue ;
231
238
}
232
239
233
240
CborValue name;
234
241
// chechk for the if the a property has a name, if yes Cbor value name will properly updated
235
242
cbor_value_map_find_value (&recursedMap, " n" , &name);
236
243
237
- // check if a property has a name, of string type, if not do nothin and skip curtrent property
244
+ // check if a property has a name, of string type, if not do nothing and skip curtrent property
238
245
if (name.type != CborTextStringType) {
239
- cbor_value_advance (&recursedMap);
246
+ err = cbor_value_advance (&recursedMap);
247
+ // problem to advance to the next array object
248
+ if (err != CborNoError)
249
+ break ;
250
+
240
251
continue ;
241
252
}
242
253
@@ -307,12 +318,20 @@ void ArduinoCloudThing::decode(uint8_t *payload, size_t length) {
307
318
if (property->callback != NULL ) {
308
319
property->callback ();
309
320
}
310
- }
321
+ }
322
+
311
323
// Continue to scan the cbor map
312
- cbor_value_advance (&recursedMap);
324
+ err = cbor_value_advance (&recursedMap);
325
+ if (err != CborNoError) {
326
+ break ;
327
+ }
313
328
}
314
329
}
330
+
331
+ if (err != CborNoError)
332
+ break ;
315
333
// Leave the current cbor object, and advance to the next one
316
- err = cbor_value_leave_container (&dataArray, &recursedMap);
334
+ cbor_value_leave_container (&dataArray, &recursedMap);
335
+
317
336
}
318
337
}
0 commit comments