[router-table] add arg bounds check to Release() (#3521)

This commit is contained in:
Jonathan Hui
2019-01-28 08:38:42 -08:00
committed by GitHub
parent cb5e076a3e
commit f9659b3733
3 changed files with 10 additions and 1 deletions
+1
View File
@@ -333,6 +333,7 @@ OTAPI void OTCALL otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8
* @param[in] aRouterId The Router ID to release. Valid range is [0, 62].
*
* @retval OT_ERROR_NONE Successfully released the router id.
* @retval OT_ERROR_INVALID_ARGS @p aRouterId is not in the range [0, 62].
* @retval OT_ERROR_INVALID_STATE The device is not currently operating as a leader.
* @retval OT_ERROR_NOT_FOUND The router id is not currently allocated.
*
+7 -1
View File
@@ -166,9 +166,15 @@ void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold
otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId)
{
otError error = OT_ERROR_NONE;
Instance &instance = *static_cast<Instance *>(aInstance);
return instance.GetThreadNetif().GetMle().GetRouterTable().Release(aRouterId);
VerifyOrExit(aRouterId <= Mle::kMaxRouterId, error = OT_ERROR_INVALID_ARGS);
error = instance.GetThreadNetif().GetMle().GetRouterTable().Release(aRouterId);
exit:
return error;
}
otError otThreadBecomeRouter(otInstance *aInstance)
+2
View File
@@ -261,6 +261,8 @@ otError RouterTable::Release(uint8_t aRouterId)
ThreadNetif &netif = GetNetif();
uint16_t rloc16 = Mle::Mle::GetRloc16(aRouterId);
assert(aRouterId <= Mle::kMaxRouterId);
VerifyOrExit(netif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsAllocated(aRouterId), error = OT_ERROR_NOT_FOUND);