The vulnerability was caused by a mishandling of terminal modes during password input with a timeout. Specifically, when reading a password without visual feedback (the default sudo prompt), the code did not disable the terminal's canonical mode (ICANON). In canonical mode, the TTY driver performs line buffering, collecting user input until a newline character is entered. The application used a timeout mechanism to abort the password prompt if the user was idle. When a timeout occurred, the application would terminate the read operation and restore the old terminal settings. However, any characters the user had typed were still held in the TTY driver's line buffer. Upon the application restoring the terminal state, this buffer was flushed to the standard output, causing the partial password to be displayed on the screen.
The patch addresses this by ensuring that canonical mode is always disabled when reading a password, regardless of whether visual feedback is enabled. This is done by modifying HiddenInput::new to always unset the ICANON flag. This puts the terminal in non-canonical (raw) mode, where input is available to the application character-by-character. The code was also refactored to use a single, robust function (read_unbuffered) for all password reading, which handles character processing and cleanup correctly, even in the event of a timeout, by using an ExitGuard to ensure no partial input is left on the screen.