[coap] validate token length on received messages (#4584)

Per RFC 7252:

- Treat invalid token length as a message format error.

- Rejecting a Confirmable message is effected by sending a matching
  Reset message and otherwise ignoring it.
This commit is contained in:
Jonathan Hui
2020-02-24 09:19:22 -08:00
committed by GitHub
parent 67f33091f0
commit 2dec88fc41
2 changed files with 7 additions and 0 deletions
+5
View File
@@ -439,6 +439,11 @@ void CoapBase::Receive(ot::Message &aMessage, const Ip6::MessageInfo &aMessageIn
if (message.ParseHeader() != OT_ERROR_NONE)
{
otLogDebgCoap("Failed to parse CoAP header");
if (!aMessageInfo.GetSockAddr().IsMulticast() && message.IsConfirmable())
{
SendReset(message, aMessageInfo);
}
}
else if (message.IsRequest())
{
+2
View File
@@ -255,6 +255,8 @@ otError Message::ParseHeader(void)
GetHelpData().mHeaderOffset = GetOffset();
Read(GetHelpData().mHeaderOffset, sizeof(GetHelpData().mHeader), &GetHelpData().mHeader);
VerifyOrExit(GetTokenLength() <= kMaxTokenLength, error = OT_ERROR_PARSE);
SuccessOrExit(error = iterator.Init(this));
for (const otCoapOption *option = iterator.GetFirstOption(); option != NULL; option = iterator.GetNextOption())
{