Markus Schmidt
2019-Apr-26 14:19 UTC
[PATCH] channels.c - check for same rfd/wfd/efd when setting the fds to nonblocking
In channels.c, the function channel_register_fds is called with three fds (efd, wfd, rfd), which can be the same fd. At the beginning of the function, when calling fcntl(xxx, F_SETFD, FD_CLOEXEC); there is a check that the function isn't called twice if some of the same fds are the same (e.g. when rfd and wfd are identical). Further down, another function is called on the fds: set_nonblock(xxx); There the check isn't performed. This is bascially inconsequential, because set_nonblock() checks if the fd is already set as nonblocking, but for code clarity I would suggest the following patch (it's attached as well): diff --git a/channels.c b/channels.c index 0a32cb2..152a1fd 100644 --- a/channels.c +++ b/channels.c @@ -336,9 +336,9 @@ channel_register_fds(struct ssh *ssh, Channel *c, int rfd, int wfd, int efd, if (nonblock) { if (rfd != -1) set_nonblock(rfd); - if (wfd != -1) + if (wfd != -1 && wfd != rfd) set_nonblock(wfd); - if (efd != -1) + if (efd != -1 && efd != rfd && efd != wfd) set_nonblock(efd); } } -------------- next part -------------- diff --git a/channels.c b/channels.c index 0a32cb2..152a1fd 100644 --- a/channels.c +++ b/channels.c @@ -336,9 +336,9 @@ channel_register_fds(struct ssh *ssh, Channel *c, int rfd, int wfd, int efd, if (nonblock) { if (rfd != -1) set_nonblock(rfd); - if (wfd != -1) + if (wfd != -1 && wfd != rfd) set_nonblock(wfd); - if (efd != -1) + if (efd != -1 && efd != rfd && efd != wfd) set_nonblock(efd); } }