From bb56fa906a09408acc3787ae54969270e43a2454 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Tue, 17 Sep 2019 17:11:49 -0700 Subject: [PATCH] [meshcop] enforce max length on commissioner id (#4178) --- src/core/meshcop/leader.cpp | 5 +++++ src/core/meshcop/meshcop_tlvs.hpp | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/meshcop/leader.cpp b/src/core/meshcop/leader.cpp index fd5ba0e98..618707f56 100644 --- a/src/core/meshcop/leader.cpp +++ b/src/core/meshcop/leader.cpp @@ -107,6 +107,11 @@ void Leader::HandlePetition(Coap::Message &aMessage, const Ip6::MessageInfo &aMe mCommissionerId = commissionerId; + if (mCommissionerId.GetLength() > CommissionerIdTlv::kMaxLength) + { + mCommissionerId.SetLength(CommissionerIdTlv::kMaxLength); + } + state = StateTlv::kAccept; mTimer.Start(TimerMilli::SecToMsec(kTimeoutLeaderPetition)); diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 39579af4d..35158446f 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -824,6 +824,11 @@ OT_TOOL_PACKED_BEGIN class CommissionerIdTlv : public Tlv { public: + enum + { + kMaxLength = 64, ///< maximum length (bytes) + }; + /** * This method initializes the TLV. * @@ -867,11 +872,6 @@ public: } private: - enum - { - kMaxLength = 64, - }; - char mCommissionerId[kMaxLength]; } OT_TOOL_PACKED_END;