Skip to content

Make comm_timer_disable() safe to call repeatedly - #6

Open
rtrappman-dev wants to merge 1 commit into
firewalla:v1.25from
rtrappman-dev:fix/comm_timer_disable()
Open

rtrappman-dev wants to merge 1 commit into
firewalla:v1.25from
rtrappman-dev:fix/comm_timer_disable()

Conversation

@rtrappman-dev

Copy link
Copy Markdown

Summary

Make comm_timer_disable() idempotent by deleting the underlying event only when the timer is currently enabled.

The existing implementation unconditionally called ub_timer_del(), even when the timer had already been disabled. Repeated disable/delete sequences could therefore attempt to remove an event more than once, potentially causing event corruption or use-after-free behavior.

Changes

  • Check timer->ev_timer->enabled before calling ub_timer_del().
  • Clear the enabled state only when an active timer is actually disabled.
  • Preserve the existing NULL-timer handling.

Security / Reliability Impact

This hardens the asynchronous event lifecycle against double deletion of timer events.

comm_timer_disable() is used across timeout, retry, cleanup, and error-handling paths, where repeated disable operations can legitimately occur. Making the operation idempotent prevents invalid event deletion and reduces the risk of event-state corruption and use-after-free conditions.

Testing

The change was verified against the fix/comm_timer_disable() branch and preserves the existing timer lifecycle semantics:

  • NULL timers remain safely ignored.
  • Active timers are disabled and have their event removed.
  • Already-disabled timers are left untouched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant