From: Simon Tatham Date: Wed, 25 Nov 2015 18:18:45 +0000 (+0000) Subject: Avoid passing -1 as an fd to uxsel_set(). X-Git-Tag: 0.68~309 X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=6c9aa9be32a44d1b2ffd02d211e6e76ec328ee76;p=PuTTY.git Avoid passing -1 as an fd to uxsel_set(). 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! --- diff --git a/unix/uxproxy.c b/unix/uxproxy.c index 0460522e..f92c459b 100644 --- a/unix/uxproxy.c +++ b/unix/uxproxy.c @@ -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); diff --git a/unix/uxsel.c b/unix/uxsel.c index fa48507f..ef25cdb5 100644 --- a/unix/uxsel.c +++ b/unix/uxsel.c @@ -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) {