From 0e9dbcbc77674304d8a6a6dc3c1d023687a8beeb Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Thu, 2 May 2024 22:30:39 +0200 Subject: [PATCH] Replace use of stat() with fstat() For better security. --- src/tty.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tty.c b/src/tty.c index f2d123e..96b62ad 100644 --- a/src/tty.c +++ b/src/tty.c @@ -1332,7 +1332,13 @@ static bool is_serial_device(const char *format, ...) return false; } - if (stat(filename, &st) != 0) + fd = open(filename, O_RDONLY | O_NONBLOCK | O_NOCTTY); + if (fd == -1) + { + return false; + } + + if (fstat(fd, &st) == -1) { return false; } @@ -1343,12 +1349,6 @@ static bool is_serial_device(const char *format, ...) return false; } - fd = open(filename, O_RDONLY | O_NONBLOCK | O_NOCTTY); - if (fd == -1) - { - return false; - } - // Make sure it is a tty status = isatty(fd); if (status == 0)