Skip to content

Commit

Permalink
[msg] Fix project-chip#15799 - Skip over MX and SX extension blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
turon committed Mar 16, 2022
1 parent 1fd1cb4 commit 0926d1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/transport/raw/MessageHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ CHIP_ERROR PacketHeader::Decode(const uint8_t * const data, uint16_t size, uint1
mDestinationGroupId.ClearValue();
}

if (mSecFlags.Has(Header::SecFlagValues::kMsgExtensionFlag))
{
// If present, skip over Message Extension block.
// Spec 4.4.1.8. Message Extensions (variable)
uint16_t mxLength;
SuccessOrExit(err = reader.Read16(&mxLength).StatusCode());
VerifyOrExit(mxLength <= reader.Remaining(), err = CHIP_ERROR_INTERNAL);
reader.Skip(mxLength);
}

octets_read = static_cast<uint16_t>(reader.OctetsRead());
VerifyOrExit(octets_read == EncodeSizeBytes(), err = CHIP_ERROR_INTERNAL);
*decode_len = octets_read;
Expand Down Expand Up @@ -258,6 +268,16 @@ CHIP_ERROR PayloadHeader::Decode(const uint8_t * const data, uint16_t size, uint
mAckMessageCounter.ClearValue();
}

if (mExchangeFlags.Has(Header::ExFlagValues::kExchangeFlag_SecuredExtension))
{
// If present, skip over Secured Extension block.
// Spec 4.4.3.7. Secured Extensions (variable)
uint16_t sxLength;
SuccessOrExit(err = reader.Read16(&sxLength).StatusCode());
VerifyOrExit(sxLength <= reader.Remaining(), err = CHIP_ERROR_INTERNAL);
reader.Skip(sxLength);
}

octets_read = static_cast<uint16_t>(reader.OctetsRead());
VerifyOrExit(octets_read == EncodeSizeBytes(), err = CHIP_ERROR_INTERNAL);
*decode_len = octets_read;
Expand Down
3 changes: 3 additions & 0 deletions src/transport/raw/MessageHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ enum class ExFlagValues : uint8_t
/// Set when current message is requesting an acknowledgment from the recipient.
kExchangeFlag_NeedsAck = 0x04,

/// Secured Extension block is present.
kExchangeFlag_SecuredExtension = 0x08,

/// Set when a vendor id is prepended to the Message Protocol Id field.
kExchangeFlag_VendorIdPresent = 0x10,
};
Expand Down

0 comments on commit 0926d1c

Please sign in to comment.