handlePtyEvent casts udata pointer without validation — potential stale pointerhandlePtyEvent casts udata pointer without validation — potential stale pointerFile: src/server/server.zig:228
Severity: MEDIUM
Status: ✅ FIXED — added isPaneValid helper to check if a pane is still alive before using its pointer cast from udata.
fn handlePtyEvent(self: *Server, ev: loop_mod.PollEvent) bool {
if (ev.fd == self.listener_fd or ev.fd == self.stdin_fd) return false;
for (self.client_fds.items) |cfd| {
if (ev.fd == cfd) return false;
}
const pane: *Pane = @ptrCast(@alignCast(ev.udata orelse return false));
udata was set to *Pane in watchPanePty. By elimination (not listener, not stdin, not client fd), the code assumes the fd must be a PTY fd with a valid pane pointer. If a race condition exists where a pane is destroyed but its fd is still in the poll set (e.g. between removeFd in handlePtyEvent and the next pollOnce), udata could point to freed memory. Arena allocation masks this (memory is not actually freed), but it’s a semantic issue that could become a real crash if allocation strategy changes.