[router-table] check num active routers before allocating (#2723)

Credit to OSS-Fuzz.
This commit is contained in:
Jonathan Hui
2018-05-17 20:05:58 -07:00
committed by GitHub
parent 65d6c98037
commit 52644515a6
+4 -8
View File
@@ -193,24 +193,19 @@ void RouterTable::UpdateAllocation(void)
Router *RouterTable::Allocate(void)
{
Router *rval = NULL;
uint8_t numAllocated = 0;
uint8_t numAvailable = 0;
uint8_t freeBit;
// count available router ids
for (uint8_t i = 0; i <= Mle::kMaxRouterId; i++)
{
if (IsAllocated(i))
{
numAllocated++;
}
else if (mRouterIdReuseDelay[i] == 0)
if (!IsAllocated(i) && mRouterIdReuseDelay[i] == 0)
{
numAvailable++;
}
}
VerifyOrExit(numAllocated < Mle::kMaxRouters && numAvailable > 0);
VerifyOrExit(mActiveRouterCount < Mle::kMaxRouters && numAvailable > 0);
// choose available router id at random
freeBit = Random::GetUint8InRange(0, numAvailable);
@@ -241,7 +236,8 @@ Router *RouterTable::Allocate(uint8_t aRouterId)
{
Router *rval = NULL;
VerifyOrExit(aRouterId <= Mle::kMaxRouterId && !IsAllocated(aRouterId) && mRouterIdReuseDelay[aRouterId] == 0);
VerifyOrExit(aRouterId <= Mle::kMaxRouterId && mActiveRouterCount < Mle::kMaxRouters && !IsAllocated(aRouterId) &&
mRouterIdReuseDelay[aRouterId] == 0);
mAllocatedRouterIds[aRouterId / 8] |= 1 << (aRouterId % 8);
UpdateAllocation();