Reject directory paths passed as tty device

When a directory path like /dev/foo is passed to tio, it silently
accepts it and appears to connect successfully, giving no indication
that the path is not a tty device. Check if the device path is a
directory before attempting to open it and exit with a clear error
message if so.

Fixes #359
This commit is contained in:
Graham Christensen 2026-02-08 10:05:20 -05:00
parent 6fb3a64ba2
commit 91f81d2665

View file

@ -2536,6 +2536,13 @@ int tty_connect(void)
char* now = NULL; char* now = NULL;
struct timeval tval_before = {}, tval_now, tval_result; struct timeval tval_before = {}, tval_now, tval_result;
/* Check that device is not a directory */
if (fs_dir_exists(device_name))
{
tio_error_printf("Device path '%s' is a directory, not a tty device", device_name);
exit(EXIT_FAILURE);
}
/* Open tty device */ /* Open tty device */
device_fd = open(device_name, O_RDWR | O_NOCTTY | O_NONBLOCK); device_fd = open(device_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (device_fd < 0) if (device_fd < 0)