mirror of
https://github.com/espressif/openthread.git
synced 2026-09-07 09:40:12 +00:00
Reject MGMT_ACTIVE_SET.req that includes fields affecting connectivity (#665)
This commit is contained in:
@@ -245,30 +245,38 @@ void DatasetManager::HandleSet(Coap::Header &aHeader, Message &aMessage, const I
|
||||
Tlv tlv;
|
||||
Timestamp timestamp;
|
||||
uint16_t offset = aMessage.GetOffset();
|
||||
uint8_t type;
|
||||
Tlv::Type type;
|
||||
StateTlv::State state = StateTlv::kAccept;
|
||||
|
||||
VerifyOrExit(mMle.GetDeviceState() == Mle::kDeviceStateLeader, state = StateTlv::kReject);
|
||||
|
||||
type = static_cast<uint8_t>(strcmp(mUriSet,
|
||||
OPENTHREAD_URI_ACTIVE_SET) == 0 ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp);
|
||||
type = (strcmp(mUriSet, OPENTHREAD_URI_ACTIVE_SET) == 0 ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp);
|
||||
|
||||
while (offset < aMessage.GetLength())
|
||||
{
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
Tlv::Type tlvType;
|
||||
|
||||
if (tlv.GetType() == type)
|
||||
aMessage.Read(offset, sizeof(tlv), &tlv);
|
||||
tlvType = tlv.GetType();
|
||||
|
||||
if (tlvType == type)
|
||||
{
|
||||
aMessage.Read(offset + sizeof(Tlv), sizeof(timestamp), ×tamp);
|
||||
break;
|
||||
}
|
||||
|
||||
// verify the request does not include fields that affect connectivity
|
||||
if (tlvType == Tlv::kChannel || tlvType == Tlv::kMeshLocalPrefix ||
|
||||
tlvType == Tlv::kPanId || tlvType == Tlv::kNetworkMasterKey)
|
||||
{
|
||||
ExitNow(state = StateTlv::kReject);
|
||||
}
|
||||
|
||||
offset += sizeof(tlv) + tlv.GetLength();
|
||||
}
|
||||
|
||||
// verify the request includes a timestamp that is ahead of the locally stored value
|
||||
VerifyOrExit(offset < aMessage.GetLength() && (mLocal.GetTimestamp() == NULL ||
|
||||
mLocal.GetTimestamp()->Compare(timestamp) > 0), state = StateTlv::kReject);
|
||||
VerifyOrExit(offset == aMessage.GetLength() && (mLocal.GetTimestamp() == NULL ||
|
||||
mLocal.GetTimestamp()->Compare(timestamp) > 0), state = StateTlv::kReject);
|
||||
|
||||
mLocal.Set(aMessage, aMessage.GetOffset(), static_cast<uint8_t>(aMessage.GetLength() - aMessage.GetOffset()));
|
||||
mNetwork = mLocal;
|
||||
|
||||
Reference in New Issue
Block a user