]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Avoid passing -1 as an fd to uxsel_set().
authorSimon Tatham <anakin@pobox.com>
Wed, 25 Nov 2015 18:18:45 +0000 (18:18 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 25 Nov 2015 18:18:45 +0000 (18:18 +0000)
I'd missed out an if statement in the Unix proxy stderr code
introduced by commit 297efff30, causing ret->cmd_err to be passed to
uxsel_set even when it was -1 (which happened in the non-GUI tools).
Unfortunately, putting a negative fd into the uxsel tree has really
bad effects, because the first_fd / next_fd interface returns a
negative number to signal end-of-list - and since the uxsel tree is
sorted by fd, that happens _immediately_.

Added the missing if statement, and also an assertion to make sure we
never pass -1 to uxsel_set by mistake again!

unix/uxproxy.c
unix/uxsel.c

index 0460522e421f6f370ae9c710bb11dd2214681b20..f92c459be284ee341a35fda4c3e61b14690b75ec 100644 (file)
@@ -405,7 +405,8 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
         add234(localproxy_by_errfd, ret);
 
     uxsel_set(ret->from_cmd, 1, localproxy_select_result);
-    uxsel_set(ret->cmd_err, 1, localproxy_select_result);
+    if (ret->cmd_err >= 0)
+        uxsel_set(ret->cmd_err, 1, localproxy_select_result);
 
     /* We are responsible for this and don't need it any more */
     sk_addr_free(addr);
index fa48507fced4a0590fa557a192d411c9c6888fca..ef25cdb574e2a6cf7fe4bb95112be1e05e52b947 100644 (file)
@@ -64,6 +64,8 @@ void uxsel_set(int fd, int rwx, uxsel_callback_fn callback)
 {
     struct fd *newfd;
 
+    assert(fd >= 0);
+
     uxsel_del(fd);
 
     if (rwx) {