[6lowpan] return OT_ERROR_PARSE on MeshHeader::Init() failures (#3796)

This commit is contained in:
Jonathan Hui
2019-05-06 08:48:28 -07:00
committed by GitHub
parent 6f679e8fb0
commit 9368ea6c3a
2 changed files with 11 additions and 11 deletions
+6 -6
View File
@@ -1210,13 +1210,13 @@ otError MeshHeader::Init(const uint8_t *aFrame, uint8_t aFrameLength)
{
otError error = OT_ERROR_NONE;
VerifyOrExit(aFrameLength >= 1, error = OT_ERROR_FAILED);
VerifyOrExit(aFrameLength >= 1, error = OT_ERROR_PARSE);
mDispatchHopsLeft = *aFrame++;
aFrameLength--;
if (IsDeepHopsLeftField())
{
VerifyOrExit(aFrameLength >= 1, error = OT_ERROR_FAILED);
VerifyOrExit(aFrameLength >= 1, error = OT_ERROR_PARSE);
mDeepHopsLeft = *aFrame++;
aFrameLength--;
}
@@ -1225,7 +1225,7 @@ otError MeshHeader::Init(const uint8_t *aFrame, uint8_t aFrameLength)
mDeepHopsLeft = 0;
}
VerifyOrExit(aFrameLength >= sizeof(mAddress), error = OT_ERROR_FAILED);
VerifyOrExit(aFrameLength >= sizeof(mAddress), error = OT_ERROR_PARSE);
memcpy(&mAddress, aFrame, sizeof(mAddress));
exit:
@@ -1239,13 +1239,13 @@ otError MeshHeader::Init(const Message &aMessage)
uint16_t bytesRead;
bytesRead = aMessage.Read(offset, sizeof(mDispatchHopsLeft), &mDispatchHopsLeft);
VerifyOrExit(bytesRead == sizeof(mDispatchHopsLeft), error = OT_ERROR_FAILED);
VerifyOrExit(bytesRead == sizeof(mDispatchHopsLeft), error = OT_ERROR_PARSE);
offset += bytesRead;
if (IsDeepHopsLeftField())
{
bytesRead = aMessage.Read(offset, sizeof(mDeepHopsLeft), &mDeepHopsLeft);
VerifyOrExit(bytesRead == sizeof(mDeepHopsLeft), error = OT_ERROR_FAILED);
VerifyOrExit(bytesRead == sizeof(mDeepHopsLeft), error = OT_ERROR_PARSE);
offset += bytesRead;
}
else
@@ -1254,7 +1254,7 @@ otError MeshHeader::Init(const Message &aMessage)
}
bytesRead = aMessage.Read(offset, sizeof(mAddress), &mAddress);
VerifyOrExit(bytesRead == sizeof(mAddress), error = OT_ERROR_FAILED);
VerifyOrExit(bytesRead == sizeof(mAddress), error = OT_ERROR_PARSE);
exit:
return error;
+5 -5
View File
@@ -417,7 +417,7 @@ public:
* @param[in] aFrameLength The length of the frame.
*
* @retval OT_ERROR_NONE Mesh Header initialized successfully.
* @retval OT_ERROR_FAILED Mesh header could not be initialized from @p aFrame (e.g., frame not long enough).
* @retval OT_ERROR_PARSE Mesh Header could not be parsed from @p aFrame.
*
*/
otError Init(const uint8_t *aFrame, uint8_t aFrameLength);
@@ -427,8 +427,8 @@ public:
*
* @param[in] aMessage The message object.
*
* @retval OT_ERROR_NONE Mesh Header initialized successfully.
* @retval OT_ERROR_FAILED Mesh header could not be initialized from @ aMessage(e.g., not long enough).
* @retval OT_ERROR_NONE Mesh Header initialized successfully.
* @retval OT_ERROR_PARSE Mesh Header could not be parsed from @p aMessage.
*
*/
otError Init(const Message &aMessage);
@@ -606,7 +606,7 @@ public:
* @param[in] aFrameLength The length of the frame.
*
* @retval OT_ERROR_NONE Fragment Header initialized successfully.
* @retval OT_ERROR_PARSE Fragment header could not be initialized from @p aFrame (e.g., frame not long enough).
* @retval OT_ERROR_PARSE Fragment header could not be parsed from @p aFrame.
*
*/
otError Init(const uint8_t *aFrame, uint8_t aFrameLength);
@@ -618,7 +618,7 @@ public:
* @param[in] aOffset An offset into the message to read the header.
*
* @retval OT_ERROR_NONE Fragment Header initialized successfully.
* @retval OT_ERROR_PARSE Fragment header could not be initialized (e.g., no frag header or message too short).
* @retval OT_ERROR_PARSE Fragment header could not be parsed from @p aMessage.
*
*/
otError Init(const Message &aMessage, uint16_t aOffset);