From 5c3a07e8e6455c59b1f5ce7df332aab9cb396cf0 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 18 Oct 2017 23:06:04 +0200 Subject: [PATCH] tty_exist(): Simplify, no need to call access() and then open() Found by Coverity Scan, classified as security issue but was just unnecessary overhead. Signed-off-by: Joachim Nilsson --- src/tty.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/tty.c b/src/tty.c index 287a6073..c1198676 100644 --- a/src/tty.c +++ b/src/tty.c @@ -345,24 +345,18 @@ tty_node_t *tty_find_by_pid(pid_t pid) static int tty_exist(char *dev) { - int fd; + int fd, result; struct termios c; - if (access(dev, F_OK)) - return 1; - - fd = open(dev, O_RDONLY); + fd = open(dev, O_RDWR); if (-1 == fd) return 1; /* XXX: Add check for errno == EIO? */ - if (tcgetattr(fd, &c)) { - close(fd); - return 1; - } + result = tcgetattr(fd, &c); close(fd); - return 0; + return result; } void tty_start(finit_tty_t *tty)