Skip to content

Correct backspace for multibyte characters#1451

Merged
squell merged 5 commits into
mainfrom
enh-password-feedback
Feb 13, 2026
Merged

Correct backspace for multibyte characters#1451
squell merged 5 commits into
mainfrom
enh-password-feedback

Conversation

@squell

@squell squell commented Feb 11, 2026

Copy link
Copy Markdown
Member

Since we use a very low-level password entry we need to take care of backspaces, kill characters, etc; but also this. This function conservatively only deals with UTF8 (and non-UTF8 sequences will simply continue to be seen as individual bytes).

This same behaviour is in ogsudo; if we agree on this fix I'll attempt to contribute it back there as well.

Note that the fix does not use the current locale, since the encoding that a password arrives in is determined by the terminal the user has than the local LC_CTYPE setting. And normally a mismatch between that is noticeable, but not so much in the password prompt since that is silent.

So the solution is that the multibyte detection is heuristic in the sense that:

  • Correct UTF8 input will be handled correctly.
  • All likely single-byte input will be handled correctly (e.g. påsswørd if it is in ISO8859-1), except if it contains mojibake such as pȧsswørd (but then the most likely intent of the user was to indeed pȧsswørd)
  • Output that mixes Latin1 and non-UTF8: the heuristic doesn't look at the count bits of the UTF8 lead byte; we could add that but at the same time, in this scenario someone deserves to have unpredictable behaviour when typing backspace on the password prompt.
  • I believe the only other relevant multibyte encoding is EUC, but that is, afaict, really on its way out. But we could add support for that encoding format in the similar way if needed.

@squell squell added this to the i18n milestone Feb 11, 2026
@squell squell added C-pam PAM library minor minor issue, PR without an issue labels Feb 11, 2026
Comment thread src/pam/rpassword.rs Outdated
Comment thread src/pam/rpassword.rs Outdated
Comment thread src/pam/rpassword.rs Outdated
Comment thread src/pam/rpassword.rs Outdated
@squell squell marked this pull request as draft February 11, 2026 17:31
@squell

This comment was marked as outdated.

@squell squell force-pushed the enh-password-feedback branch 2 times, most recently from 33d2e7b to dfdb7c7 Compare February 11, 2026 20:17
@squell squell marked this pull request as ready for review February 11, 2026 20:17
@squell squell force-pushed the enh-password-feedback branch from dfdb7c7 to 2d63112 Compare February 11, 2026 20:26
@squell

squell commented Feb 11, 2026

Copy link
Copy Markdown
Member Author

This can be reviewed commit by commit; the first has the most churn but should be a neutral change; the second is neutral as well (but the final change necessary in read_unbuffered to show that the logical changes are indeed very minor)

@squell squell force-pushed the enh-password-feedback branch from 2d63112 to 7c145ea Compare February 11, 2026 20:41
@squell squell force-pushed the enh-password-feedback branch from 7c145ea to 5949b9f Compare February 11, 2026 20:42
@squell squell requested a review from bjorn3 February 12, 2026 14:07
Comment thread src/pam/rpassword.rs
Comment thread src/pam/rpassword.rs Outdated
Comment thread src/pam/rpassword.rs
Comment thread src/pam/rpassword.rs
@squell

squell commented Feb 12, 2026

Copy link
Copy Markdown
Member Author

I've also compared systemd-ask-password and even if I put everything into ISO8859-1, typing in some special characters will just disable the bulletprinter from that point onward; the above routine handles that more gracefully.

@squell

squell commented Feb 12, 2026

Copy link
Copy Markdown
Member Author

This of course made me curious, e.g. for EUC-JP: even if it is being used, would it be used for writing passwords? This Reddit thread seems to suggest not.

@squell squell merged commit b39ab06 into main Feb 13, 2026
51 of 54 checks passed
@squell squell deleted the enh-password-feedback branch February 13, 2026 09:23
@squell squell removed the minor minor issue, PR without an issue label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-pam PAM library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pwfeedback: Multi-byte UTF-8 characters display multiple masking symbols instead of one

2 participants