summaryrefslogtreecommitdiff
path: root/mux.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-09-12 06:35:31 +0000
committerDamien Miller <djm@mindrot.org>2017-09-12 17:37:03 +1000
commit9f53229c2ac97dbc6f5a03657de08a1150a9ac7e (patch)
tree4f74dc06676dc6dce2b2bc3aa6beb248a1d8def6 /mux.c
parentdbee4119b502e3f8b6cd3282c69c537fd01d8e16 (diff)
upstream commit
Make remote channel ID a u_int Previously we tracked the remote channel IDs in an int, but this is strictly incorrect: the wire protocol uses uint32 and there is nothing in-principle stopping a SSH implementation from sending, say, 0xffff0000. In practice everyone numbers their channels sequentially, so this has never been a problem. ok markus@ Upstream-ID: b9f4cd3dc53155b4a5c995c0adba7da760d03e73
Diffstat (limited to 'mux.c')
-rw-r--r--mux.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/mux.c b/mux.c
index 9eee287b9..f8510426d 100644
--- a/mux.c
+++ b/mux.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: mux.c,v 1.66 2017/09/12 06:32:07 djm Exp $ */ 1/* $OpenBSD: mux.c,v 1.67 2017/09/12 06:35:32 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -215,7 +215,8 @@ mux_master_session_cleanup_cb(struct ssh *ssh, int cid, void *unused)
215 fatal("%s: channel %d missing control channel %d", 215 fatal("%s: channel %d missing control channel %d",
216 __func__, c->self, c->ctl_chan); 216 __func__, c->self, c->ctl_chan);
217 c->ctl_chan = -1; 217 c->ctl_chan = -1;
218 cc->remote_id = -1; 218 cc->remote_id = 0;
219 cc->have_remote_id = 0;
219 chan_rcvd_oclose(ssh, cc); 220 chan_rcvd_oclose(ssh, cc);
220 } 221 }
221 channel_cancel_cleanup(ssh, c->self); 222 channel_cancel_cleanup(ssh, c->self);
@@ -231,11 +232,12 @@ mux_master_control_cleanup_cb(struct ssh *ssh, int cid, void *unused)
231 debug3("%s: entering for channel %d", __func__, cid); 232 debug3("%s: entering for channel %d", __func__, cid);
232 if (c == NULL) 233 if (c == NULL)
233 fatal("%s: channel_by_id(%i) == NULL", __func__, cid); 234 fatal("%s: channel_by_id(%i) == NULL", __func__, cid);
234 if (c->remote_id != -1) { 235 if (c->have_remote_id) {
235 if ((sc = channel_by_id(ssh, c->remote_id)) == NULL) 236 if ((sc = channel_by_id(ssh, c->remote_id)) == NULL)
236 fatal("%s: channel %d missing session channel %d", 237 fatal("%s: channel %d missing session channel %u",
237 __func__, c->self, c->remote_id); 238 __func__, c->self, c->remote_id);
238 c->remote_id = -1; 239 c->remote_id = 0;
240 c->have_remote_id = 0;
239 sc->ctl_chan = -1; 241 sc->ctl_chan = -1;
240 if (sc->type != SSH_CHANNEL_OPEN && 242 if (sc->type != SSH_CHANNEL_OPEN &&
241 sc->type != SSH_CHANNEL_OPENING) { 243 sc->type != SSH_CHANNEL_OPENING) {
@@ -413,7 +415,7 @@ process_mux_new_session(struct ssh *ssh, u_int rid,
413 new_fd[0], new_fd[1], new_fd[2]); 415 new_fd[0], new_fd[1], new_fd[2]);
414 416
415 /* XXX support multiple child sessions in future */ 417 /* XXX support multiple child sessions in future */
416 if (c->remote_id != -1) { 418 if (c->have_remote_id) {
417 debug2("%s: session already open", __func__); 419 debug2("%s: session already open", __func__);
418 /* prepare reply */ 420 /* prepare reply */
419 buffer_put_int(r, MUX_S_FAILURE); 421 buffer_put_int(r, MUX_S_FAILURE);
@@ -471,6 +473,7 @@ process_mux_new_session(struct ssh *ssh, u_int rid,
471 473
472 nc->ctl_chan = c->self; /* link session -> control channel */ 474 nc->ctl_chan = c->self; /* link session -> control channel */
473 c->remote_id = nc->self; /* link control -> session channel */ 475 c->remote_id = nc->self; /* link control -> session channel */
476 c->have_remote_id = 1;
474 477
475 if (cctx->want_tty && escape_char != 0xffffffff) { 478 if (cctx->want_tty && escape_char != 0xffffffff) {
476 channel_register_filter(ssh, nc->self, 479 channel_register_filter(ssh, nc->self,
@@ -1007,7 +1010,7 @@ process_mux_stdio_fwd(struct ssh *ssh, u_int rid,
1007 new_fd[0], new_fd[1]); 1010 new_fd[0], new_fd[1]);
1008 1011
1009 /* XXX support multiple child sessions in future */ 1012 /* XXX support multiple child sessions in future */
1010 if (c->remote_id != -1) { 1013 if (c->have_remote_id) {
1011 debug2("%s: session already open", __func__); 1014 debug2("%s: session already open", __func__);
1012 /* prepare reply */ 1015 /* prepare reply */
1013 buffer_put_int(r, MUX_S_FAILURE); 1016 buffer_put_int(r, MUX_S_FAILURE);
@@ -1043,6 +1046,7 @@ process_mux_stdio_fwd(struct ssh *ssh, u_int rid,
1043 1046
1044 nc->ctl_chan = c->self; /* link session -> control channel */ 1047 nc->ctl_chan = c->self; /* link session -> control channel */
1045 c->remote_id = nc->self; /* link control -> session channel */ 1048 c->remote_id = nc->self; /* link control -> session channel */
1049 c->have_remote_id = 1;
1046 1050
1047 debug2("%s: channel_new: %d linked to control channel %d", 1051 debug2("%s: channel_new: %d linked to control channel %d",
1048 __func__, nc->self, nc->ctl_chan); 1052 __func__, nc->self, nc->ctl_chan);