diff --git a/src/core/net/ip6_mpl.cpp b/src/core/net/ip6_mpl.cpp index 96ffff265..05e607109 100644 --- a/src/core/net/ip6_mpl.cpp +++ b/src/core/net/ip6_mpl.cpp @@ -79,16 +79,25 @@ Error Mpl::ProcessOption(Message &aMessage, const Address &aAddress, bool aIsOut Error error; OptionMpl option; - VerifyOrExit(aMessage.ReadBytes(aMessage.GetOffset(), &option, sizeof(option)) >= OptionMpl::kMinLength && - (option.GetSeedIdLength() == OptionMpl::kSeedIdLength0 || - option.GetSeedIdLength() == OptionMpl::kSeedIdLength2), - error = kErrorParse); + // Read the min size bytes first, then check the expected + // `SeedIdLength` and read the full `OptionMpl` if needed. + SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), &option, OptionMpl::kMinSize)); - if (option.GetSeedIdLength() == OptionMpl::kSeedIdLength0) + switch (option.GetSeedIdLength()) { + case OptionMpl::kSeedIdLength0: // Retrieve Seed ID from the IPv6 Source Address RLOC. VerifyOrExit(aAddress.GetIid().IsLocator(), error = kErrorDrop); option.SetSeedId(aAddress.GetIid().GetLocator()); + break; + + case OptionMpl::kSeedIdLength2: + SuccessOrExit(error = aMessage.Read(aMessage.GetOffset(), option)); + break; + + case OptionMpl::kSeedIdLength8: + case OptionMpl::kSeedIdLength16: + ExitNow(error = kErrorParse); } // Check if the MPL Data Message is new. diff --git a/src/core/net/ip6_mpl.hpp b/src/core/net/ip6_mpl.hpp index e1fbdf7b6..5688e5f0d 100644 --- a/src/core/net/ip6_mpl.hpp +++ b/src/core/net/ip6_mpl.hpp @@ -64,8 +64,8 @@ OT_TOOL_PACKED_BEGIN class OptionMpl : public OptionHeader { public: - static constexpr uint8_t kType = 0x6d; // 01 1 01101 - static constexpr uint8_t kMinLength = 2; + static constexpr uint8_t kType = 0x6d; ///< MPL option type - 01 1 01101 + static constexpr uint8_t kMinSize = (2 + sizeof(OptionHeader)); ///< Minimum size (num of bytes) of `OptionMpl` /** * This method initializes the MPL header.