From 91f81d26653bbb01db93ad2929fc30cdf30f9ca4 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 8 Feb 2026 10:05:20 -0500 Subject: [PATCH] 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 --- src/tty.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/tty.c b/src/tty.c index efda859..6a95a97 100644 --- a/src/tty.c +++ b/src/tty.c @@ -2536,6 +2536,13 @@ int tty_connect(void) char* now = NULL; 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 */ device_fd = open(device_name, O_RDWR | O_NOCTTY | O_NONBLOCK); if (device_fd < 0)