Skip to content

Commit 4152ea1

Browse files
authored
[bbr] fix overflow in Config::SelectRandomReregistrationDelay() (openthread#13128)
This commit fixes a potential `uint16_t` overflow in `Config::SelectRandomReregistrationDelay()` which could occur if `mReregistrationDelay` was set to the maximum `uint16_t` value. The `Random::NonCrypto::GetUint16InRange(lower, upper)` function includes the lower bound but excludes the upper bound. Previously, the code called `GetUint16InRange(1, mReregistrationDelay + 1)`, which would overflow the upper bound if `mReregistrationDelay` was `0xffff`. The logic is updated to `1 + GetUint16InRange(0, mReregistrationDelay)`, which safely produces a random value in the range `[1, mReregistrationDelay]` without overflow.
1 parent bd47a31 commit 4152ea1

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/core/backbone_router/bbr_leader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ uint16_t Config::SelectRandomReregistrationDelay(void) const
6666
uint16_t delay = 1;
6767

6868
VerifyOrExit(mReregistrationDelay > 1);
69-
delay = Random::NonCrypto::GetUint16InRange(1, mReregistrationDelay + 1);
69+
delay = 1 + Random::NonCrypto::GetUint16InRange(0, mReregistrationDelay);
7070

7171
exit:
7272
return delay;

0 commit comments

Comments
 (0)