Repository navigation
Reject a zero link status period at the tunable setter - #152
zigpy-review-bot wants to merge 2 commits into
Conversation
`take_decay_steps` divides by `link_status_period`, which the tunable setter accepts as zero. Activity decay now runs on received link statuses, relayed unicasts, and accepted route requests and replies, so a zero period crashed the stack on the receive path. Treat a zero period as a count lasting no time: everything decays at once, and the same instant again owes nothing.
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change addressing zero-period Zigbee activity decay.
No open issues 🎉
What changed in this PR
Prevents a zero link_status_period from causing a division-by-zero panic during Zigbee network activity decay.
Changes:
- Returns maximum decay steps when time has advanced with a zero period, and zero steps when no time has advanced.
- Adds a regression test covering zero-period decay and repeated calls at the same instant.
| File | Description |
|---|---|
crates/ziggurat-zigbee/src/nwk/activity.rs |
Handles zero periods safely in take_decay_steps and adds regression coverage. |
Review effort: Balanced
|
Tunables are effectively undocumented stack constants and their purpose is to allow low-level tweaking of the stack without rebuilding firmwares. If you choose to tweak one, crashing the stack is a possibility. I think a proper fix for this bug would be to have basic validation (e.g. greater than 0, less than 255) for tunables and to reject invalid values. |
Tunables get an optional valid range in the `tunables!` list: `set` rejects a value outside it with `InvalidValue`, leaving the stored value unchanged. `link_status_period` must be non-zero, since activity decay divides by it. This replaces the zero-period special case in `take_decay_steps`: a value the stack cannot run with is refused when it is set instead of being worked around where it is read.
|
Agreed, validating at the setter is the better fix. Pushed 403ab27: tunables can now declare a valid range in the I only gave Title and body updated to match. |
Summary
Setting the
link_status_periodtunable to 0 crashes the stack since #145:take_decay_stepsdivides by the period, and activity decay runs on received link statuses, relayed unicasts, and accepted route requests and replies, among others. The tunable setter accepted anyu32microseconds, zero included.Tunables now carry an optional valid range, and
setrejects a value outside it, so a value the stack cannot run with is refused when it is set instead of crashing it later.Changes
tunables!takes an optional; valid <range>after a field's default.Tunables::setreturnsTunableError::InvalidValue("value out of range") for a value outside that range and leaves the stored value unchanged, the same error a value that doesn't fit the type already gets, which the bridge answers with anInvalidRequeststatus.link_status_periodmust be at least 1 µs.take_decay_stepsis gone again: its code is as on dev, and its doc now says the period must be at least 1 µs.Only
link_status_periodgets a range here: it is the one tunable I found where a value the setter accepts panics the stack. The broadcast token bucket treats a zero refill interval as "no rate limit", and the jitter pairs subtract saturating, so an inverted pair does not panic either. Tighter bounds on other tunables are left for a later change.Testing
test_set_rejects_value_outside_valid_range: settinglink_status_periodto 0 is rejected and keeps the old value; 1 µs is accepted.Checks run
cargo fmt --all --checkcargo clippy --workspace --all-targets --all-features -- -D warnings -Dclippy::all -Dclippy::nurserycargo test --workspace --all-features: all pass