summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2018-02-05 05:36:50 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2018-02-05 05:36:50 +0000
commitfa7e286aa149e132efa5ce32a19b9466fadde90f (patch)
tree7b3b8e079fc5b43d8bd3db5fb0a9088be0e22b9b /usr.bin
parented89f2d6da662688a917a2fae6e9ac1dd0cc825b (diff)
The file descriptors for socket, stdin, stdout and stderr aren't
necessarily distinct, so check if they are the same to avoid closing the same fd several times. ok djm
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/ssh/channels.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c
index f10702daca4..00d9f1c5579 100644
--- a/usr.bin/ssh/channels.c
+++ b/usr.bin/ssh/channels.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.378 2018/01/23 05:27:21 djm Exp $ */
+/* $OpenBSD: channels.c,v 1.379 2018/02/05 05:36:49 tb Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -426,10 +426,15 @@ channel_close_fd(struct ssh *ssh, int *fdp)
static void
channel_close_fds(struct ssh *ssh, Channel *c)
{
+ int sock = c->sock, rfd = c->rfd, wfd = c->wfd, efd = c->efd;
+
channel_close_fd(ssh, &c->sock);
- channel_close_fd(ssh, &c->rfd);
- channel_close_fd(ssh, &c->wfd);
- channel_close_fd(ssh, &c->efd);
+ if (rfd != sock)
+ channel_close_fd(ssh, &c->rfd);
+ if (wfd != sock && wfd != rfd)
+ channel_close_fd(ssh, &c->wfd);
+ if (efd != sock && efd != rfd && efd != wfd)
+ channel_close_fd(ssh, &c->efd);
}
static void