Skip to content

Commit

Permalink
Add check to switch VTs only between K_XLATE or K_UNICODE
Browse files Browse the repository at this point in the history
Switching to K_UNICODE from other than L_XLATE can make the keyboard
unusable and possibly leak keypresses from X.

BugLink: https://launchpad.net/bugs/1803993
  • Loading branch information
Balint Reczey committed May 15, 2019
1 parent bb5ac84 commit 13a43c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/basic/terminal-util.c
Expand Up @@ -1267,11 +1267,18 @@ int vt_verify_kbmode(int fd) {
}

int vt_reset_keyboard(int fd) {
int kb;
int kb, r;

/* If we can't read the default, then default to unicode. It's 2017 after all. */
kb = vt_default_utf8() != 0 ? K_UNICODE : K_XLATE;

r = vt_verify_kbmode(fd);
if (r == -EBUSY) {
log_debug_errno(r, "Keyboard is not in XLATE or UNICODE mode, not resetting: %m");
return 0;
} else if (r < 0)
return r;

if (ioctl(fd, KDSKBMODE, kb) < 0)
return -errno;

Expand Down
7 changes: 7 additions & 0 deletions src/vconsole/vconsole-setup.c
Expand Up @@ -76,6 +76,13 @@ static int toggle_utf8(const char *name, int fd, bool utf8) {

assert(name);

r = vt_verify_kbmode(fd);
if (r == -EBUSY) {
log_warning_errno(r, "Virtual console %s is not in K_XLATE or K_UNICODE: %m", name);
return 0;
} else if (r < 0)
return log_warning_errno(r, "Failed to verify kbdmode on %s: %m", name);

r = ioctl(fd, KDSKBMODE, utf8 ? K_UNICODE : K_XLATE);
if (r < 0)
return log_warning_errno(errno, "Failed to %s UTF-8 kbdmode on %s: %m", enable_disable(utf8), name);
Expand Down

0 comments on commit 13a43c7

Please sign in to comment.