diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-06-22 12:20:05 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-06-22 12:20:05 +0200 |
commit | 6defc05f0a7226a260d7f80e6708dad1ca5b66f5 (patch) | |
tree | 3140503d08d1a50349d6c9e64b531feb070da11e /src/core | |
parent | ebac36d0751086842968424852c079a7fd197d80 (diff) | |
download | weechat-6defc05f0a7226a260d7f80e6708dad1ca5b66f5.zip |
core: fix freeze when hook_fd is called with a bad file/socket (bug #33619)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-hook.c | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index e20c0aeb9..ffea7a7ac 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -34,6 +34,8 @@ #include <sys/types.h> #include <sys/wait.h> #include <signal.h> +#include <fcntl.h> +#include <errno.h> #include "weechat.h" #include "wee-hook.h" @@ -1221,23 +1223,28 @@ hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { if (!ptr_hook->deleted) { - if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) + /* skip invalid file descriptors */ + if ((fcntl (HOOK_FD(ptr_hook,fd), F_GETFD) != -1) + || (errno != EBADF)) { - FD_SET (HOOK_FD(ptr_hook, fd), read_fds); - if (HOOK_FD(ptr_hook, fd) > max_fd) - max_fd = HOOK_FD(ptr_hook, fd); - } - if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) - { - FD_SET (HOOK_FD(ptr_hook, fd), write_fds); - if (HOOK_FD(ptr_hook, fd) > max_fd) - max_fd = HOOK_FD(ptr_hook, fd); - } - if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) - { - FD_SET (HOOK_FD(ptr_hook, fd), exception_fds); - if (HOOK_FD(ptr_hook, fd) > max_fd) - max_fd = HOOK_FD(ptr_hook, fd); + if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) + { + FD_SET (HOOK_FD(ptr_hook, fd), read_fds); + if (HOOK_FD(ptr_hook, fd) > max_fd) + max_fd = HOOK_FD(ptr_hook, fd); + } + if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) + { + FD_SET (HOOK_FD(ptr_hook, fd), write_fds); + if (HOOK_FD(ptr_hook, fd) > max_fd) + max_fd = HOOK_FD(ptr_hook, fd); + } + if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) + { + FD_SET (HOOK_FD(ptr_hook, fd), exception_fds); + if (HOOK_FD(ptr_hook, fd) > max_fd) + max_fd = HOOK_FD(ptr_hook, fd); + } } } } |