From 9368ea6c3ad966406767f31a37e56b4792406c63 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 6 May 2019 08:48:28 -0700 Subject: [PATCH] [6lowpan] return OT_ERROR_PARSE on MeshHeader::Init() failures (#3796) --- src/core/thread/lowpan.cpp | 12 ++++++------ src/core/thread/lowpan.hpp | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/core/thread/lowpan.cpp b/src/core/thread/lowpan.cpp index 13ce22e47..be770b6b6 100644 --- a/src/core/thread/lowpan.cpp +++ b/src/core/thread/lowpan.cpp @@ -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; diff --git a/src/core/thread/lowpan.hpp b/src/core/thread/lowpan.hpp index c20e6f3b6..7ca4cbe33 100644 --- a/src/core/thread/lowpan.hpp +++ b/src/core/thread/lowpan.hpp @@ -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);