mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
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:
parent
6fb3a64ba2
commit
91f81d2665
1 changed files with 7 additions and 0 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue