From 3e6dbe7cef04d89f71645e80b6d14db72ff13bf5 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 26 Jul 2017 12:15:01 -0700 Subject: [PATCH] [mac] validate channel in Mac::SetChannel() (#2030) --- src/core/api/link_api.cpp | 2 +- src/core/mac/mac.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index 803bb4114..baa718c33 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -54,7 +54,7 @@ otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel) VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE); - error = aInstance->mThreadNetif.GetMac().SetChannel(aChannel); + SuccessOrExit(error = aInstance->mThreadNetif.GetMac().SetChannel(aChannel)); aInstance->mThreadNetif.GetActiveDataset().Clear(); aInstance->mThreadNetif.GetPendingDataset().Clear(); diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 0ee80de77..ef64b7b33 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -475,7 +475,12 @@ otError Mac::SetShortAddress(ShortAddress aShortAddress) otError Mac::SetChannel(uint8_t aChannel) { + otError error = OT_ERROR_NONE; + otLogFuncEntryMsg("%d", aChannel); + + VerifyOrExit(OT_RADIO_CHANNEL_MIN <= aChannel && aChannel <= OT_RADIO_CHANNEL_MAX, error = OT_ERROR_INVALID_ARGS); + mChannel = aChannel; if (mState == kStateIdle) @@ -483,8 +488,9 @@ otError Mac::SetChannel(uint8_t aChannel) NextOperation(); } +exit: otLogFuncExit(); - return OT_ERROR_NONE; + return error; } otError Mac::SetNetworkName(const char *aNetworkName)