restore raw terminal mode on every exit path #34

Open
opened 2026-05-22 10:43:48 +00:00 by rc · 0 comments
Owner

Finding:
Raw terminal restoration is not guaranteed.

Problem:

  • Raw mode is enabled before VM start.
  • Restoration happens only in selected callbacks and quit paths.
  • Signals, unexpected run-loop return, input EOF, thread failure, or some error paths can leave the terminal altered.

Impact:

  • A failed or interrupted VM run can leave the user terminal in a broken raw state.
  • This is a high-friction failure mode for a CLI tool.

Suggested fix:

  • Make terminal mode a scoped resource with defer-style restoration in the main VM run path.
  • Add signal handling for common termination signals.
  • Restore terminal mode if the run loop returns unexpectedly.
  • Consider centralizing process exit through one cleanup function.

Relevant code:

  • src/vmz.zig: enableRawTerminalMode, restoreTerminalMode, callback exits.
Finding: Raw terminal restoration is not guaranteed. Problem: - Raw mode is enabled before VM start. - Restoration happens only in selected callbacks and quit paths. - Signals, unexpected run-loop return, input EOF, thread failure, or some error paths can leave the terminal altered. Impact: - A failed or interrupted VM run can leave the user terminal in a broken raw state. - This is a high-friction failure mode for a CLI tool. Suggested fix: - Make terminal mode a scoped resource with defer-style restoration in the main VM run path. - Add signal handling for common termination signals. - Restore terminal mode if the run loop returns unexpectedly. - Consider centralizing process exit through one cleanup function. Relevant code: - `src/vmz.zig`: `enableRawTerminalMode`, `restoreTerminalMode`, callback exits.
Sign in to join this conversation.
No labels
highprio
lowprio
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rc/vmz#34
No description provided.