1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

terminal-util: add extra validity checks that we operate on a TTY before doing so

Prompted by #19213, but not fixing it.

This is mostly paranoia that we don't do stuff on inodes that aren't
actually ttys.
This commit is contained in:
Lennart Poettering 2021-05-12 13:45:48 +02:00
parent 7eaee90286
commit e60a4a3c46

View File

@ -240,9 +240,11 @@ int reset_terminal_fd(int fd, bool switch_to_text) {
assert(fd >= 0);
/* We leave locked terminal attributes untouched, so that
* Plymouth may set whatever it wants to set, and we don't
* interfere with that. */
if (isatty(fd) < 1)
return log_debug_errno(errno, "Asked to reset a terminal that actually isn't a terminal: %m");
/* We leave locked terminal attributes untouched, so that Plymouth may set whatever it wants to set,
* and we don't interfere with that. */
/* Disable exclusive mode, just in case */
if (ioctl(fd, TIOCNXCL) < 0)
@ -1329,6 +1331,9 @@ int vt_restore(int fd) {
};
int r, q = 0;
if (isatty(fd) < 1)
return log_debug_errno(errno, "Asked to restore the VT for an fd that does not refer to a terminal: %m");
if (ioctl(fd, KDSETMODE, KD_TEXT) < 0)
q = log_debug_errno(errno, "Failed to set VT in text mode, ignoring: %m");
@ -1362,6 +1367,9 @@ int vt_release(int fd, bool restore) {
* sent by the kernel and optionally reset the VT in text and auto
* VT-switching modes. */
if (isatty(fd) < 1)
return log_debug_errno(errno, "Asked to release the VT for an fd that does not refer to a terminal: %m");
if (ioctl(fd, VT_RELDISP, 1) < 0)
return -errno;