Severity: LOW Status: Fixed
None observed. This is a defensive-hardening gap in the stale-pane defence
(bug #283/#362): the safety of every cached *Pane after a session kill
rests on an ordering convention, not on an explicit invalidation, and the
validator itself is an address comparison that cannot detect arena reuse.
isPaneValid (server.zig:717-726) walks all live sessions/windows/panes and
returns p.valid only when p == pane. Two consequences:
valid is only cleared on two teardown paths. Session.killWindow
(session.zig:130) and the removePane branch of destroyPane
(server.zig:948) set pane.valid = false before deinit. killSession
(server.zig:3242-3263) and killAllSessions (server.zig:3265-3281)
destroy panes without clearing it — they rely on the pane leaving the live
lists, plus clearPaneMouseRefsBulk for the cached mouse pointers.Pane (arena reuse), a stale cached pointer
compares equal to the new live pane and isPaneValid returns true —
blessing a pointer to the wrong object. handlePtyEvent would then
feedPty stale udata into the wrong pane (or worse, if the pty fd was
also recycled).What keeps this safe today is the ordering inside killSession/killAllSessions:
the pty master fds are removed from the loop (server.zig:3247-3253, 3266-3273)
before deinit, so no subsequent poll can deliver an event carrying the
freed pane’s udata. That ordering is load-bearing but not enforced by any
type or assertion.
pane.valid = false for every pane in killSession/killAllSessions
before teardown (matching Session.killWindow), so isPaneValid returns
false for freed panes even if the address is reused.isPaneValid fail closed (return false) instead of
trusting p.valid when the comparison matches a freshly reused address —
though this requires a generation/epoch counter per pane to be robust.*Pane is not treated as live after arena reuse.Fixed:
src/server/server.zig, killSession and killAllSessions now explicitly set pane.valid = false on every pane before unregistration/deinit.src/session.zig, Session.deinit sets p.valid = false for every pane before p.deinit().src/window.zig, Pane.deinit sets self.valid = false.isPaneValid respects pane.valid flag and session teardown clears it — bug #449 verifies that isPaneValid rejects invalidated panes and confirms teardown paths clear valid.