File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -315,17 +315,20 @@ static void mb2_parse_info_request_tag(void* tag) {
315315 }
316316}
317317
318- static void mb2_dump_tags (void * mbTags ) {
318+ static void mb2_dump_tags (void * mbTags , uint32_t tags_len ) {
319319 struct mb2_tag * tag = (struct mb2_tag * )mbTags ;
320+ uint8_t * end = (uint8_t * )mbTags + tags_len ;
320321
321- while (tag -> type != 0 ) {
322+ while (( uint8_t * ) tag + sizeof ( * tag ) <= end && tag -> type != 0 ) {
322323 MB2_DEBUG_PRINTF ("Tag Type: %u\r\n" , tag -> type );
323324 MB2_DEBUG_PRINTF ("Tag Flags: 0x%x\r\n" , tag -> flags );
324325 MB2_DEBUG_PRINTF ("Tag Size: %u\r\n" , tag -> size );
325326
326327 if (tag -> type == MB2_TAG_TYPE_INFO_REQ )
327328 mb2_parse_info_request_tag (tag );
328329
330+ if (tag -> size < sizeof (* tag ))
331+ break ;
329332 tag = (struct mb2_tag * )mb2_align_address_up ((uint8_t * )tag + tag -> size ,
330333 8 );
331334 }
@@ -341,7 +344,7 @@ static void mb2_dump_header(void* mbHeader) {
341344 MB2_DEBUG_PRINTF ("Checksum: 0x%x\r\n" , header -> checksum );
342345
343346 tags = (uint8_t * )header + sizeof (* header );
344- mb2_dump_tags (tags );
347+ mb2_dump_tags (tags , header -> header_length - sizeof ( * header ) );
345348}
346349#endif /* DEBUG_MB2 */
347350
You can’t perform that action at this time.
0 commit comments