]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: check whether the specified fd is a tty before chowning/chmoding it (#3457)
authorLennart Poettering <lennart@poettering.net>
Thu, 9 Jun 2016 08:01:16 +0000 (10:01 +0200)
committerDaniel Mack <github@zonque.org>
Thu, 9 Jun 2016 08:01:16 +0000 (10:01 +0200)
Let's add an extra safety check before we chmod/chown a TTY to the right user,
as we might end up having connected something to STDIN/STDOUT that is actually
not a TTY, even though this might have been requested, due to permissive
StandardInput= settings or transient service activation with fds passed in.

Fixes:

https://bugs.freedesktop.org/show_bug.cgi?id=85255

src/core/execute.c

index 2cef70e6683510b5805d1ba26076abc6a66d4ac3..e718c43df9e1a363886ddc0212c048b23ed39a67 100644 (file)
@@ -552,6 +552,10 @@ static int chown_terminal(int fd, uid_t uid) {
 
         assert(fd >= 0);
 
+        /* Before we chown/chmod the TTY, let's ensure this is actually a tty */
+        if (isatty(fd) < 1)
+                return 0;
+
         /* This might fail. What matters are the results. */
         (void) fchown(fd, uid, -1);
         (void) fchmod(fd, TTY_MODE);