[PATCH] channels.c - check for same rfd/wfd/efd when setting the fds to nonblocking

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

 




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);
 	}
 }
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);
 	}
 }
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@xxxxxxxxxxx
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux