Replace use of stat() with fstat()

For better security.
This commit is contained in:
Martin Lund 2024-05-02 22:30:39 +02:00
parent 68c78222e1
commit 0e9dbcbc77

View file

@ -1332,7 +1332,13 @@ static bool is_serial_device(const char *format, ...)
return false; 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; return false;
} }
@ -1343,12 +1349,6 @@ static bool is_serial_device(const char *format, ...)
return false; return false;
} }
fd = open(filename, O_RDONLY | O_NONBLOCK | O_NOCTTY);
if (fd == -1)
{
return false;
}
// Make sure it is a tty // Make sure it is a tty
status = isatty(fd); status = isatty(fd);
if (status == 0) if (status == 0)