diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-11 16:05:56 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-03-11 16:45:51 +0100 |
commit | fc9e66e555f8520b14a2f25335f4e03b349f70a3 (patch) | |
tree | 2fbe209ba6d704f24a88a236ed6225e1c72a8473 /src/unix/tty.c | |
parent | 1df46fe47869244db44e90d2ced5685a4c921775 (diff) | |
download | libuv-fc9e66e555f8520b14a2f25335f4e03b349f70a3.tar.gz libuv-fc9e66e555f8520b14a2f25335f4e03b349f70a3.zip |
unix: reject non-tty fds in uv_tty_init()
Reject file descriptors that correspond to regular files or char/block
devices. Such file descriptors are incompatible with epoll and trigger
a run-time assert.
Fixes: https://github.com/libuv/libuv/issues/255
PR-URL: https://github.com/libuv/libuv/pull/259
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Diffstat (limited to 'src/unix/tty.c')
-rw-r--r-- | src/unix/tty.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/unix/tty.c b/src/unix/tty.c index 9038d85a..7783548a 100644 --- a/src/unix/tty.c +++ b/src/unix/tty.c @@ -35,10 +35,19 @@ static uv_spinlock_t termios_spinlock = UV_SPINLOCK_INITIALIZER; int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) { + uv_handle_type type; int flags; int newfd; int r; + /* File descriptors that refer to files cannot be monitored with epoll. + * That restriction also applies to character devices like /dev/random + * (but obviously not /dev/tty.) + */ + type = uv_guess_handle(fd); + if (type == UV_FILE || type == UV_UNKNOWN_HANDLE) + return -EINVAL; + flags = 0; newfd = -1; @@ -54,7 +63,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) { * different struct file, hence changing its properties doesn't affect * other processes. */ - if (isatty(fd)) { + if (type == UV_TTY) { r = uv__open_cloexec("/dev/tty", O_RDWR); if (r < 0) { |