summaryrefslogtreecommitdiff
path: root/channels.c
diff options
context:
space:
mode:
Diffstat (limited to 'channels.c')
-rw-r--r--channels.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/channels.c b/channels.c
index 758ea506d..1ec6074b5 100644
--- a/channels.c
+++ b/channels.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: channels.c,v 1.136 2001/10/04 15:05:40 markus Exp $"); 42RCSID("$OpenBSD: channels.c,v 1.137 2001/10/07 17:49:40 markus Exp $");
43 43
44#include "ssh.h" 44#include "ssh.h"
45#include "ssh1.h" 45#include "ssh1.h"
@@ -241,6 +241,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
241 } 241 }
242 /* Initialize and return new channel. */ 242 /* Initialize and return new channel. */
243 c = channels[found] = xmalloc(sizeof(Channel)); 243 c = channels[found] = xmalloc(sizeof(Channel));
244 memset(c, 0, sizeof(Channel));
244 buffer_init(&c->input); 245 buffer_init(&c->input);
245 buffer_init(&c->output); 246 buffer_init(&c->output);
246 buffer_init(&c->extended); 247 buffer_init(&c->extended);
@@ -974,7 +975,7 @@ channel_pre_dynamic(Channel *c, fd_set * readset, fd_set * writeset)
974 int have, ret; 975 int have, ret;
975 976
976 have = buffer_len(&c->input); 977 have = buffer_len(&c->input);
977 978 c->delayed = 0;
978 debug2("channel %d: pre_dynamic: have %d", c->self, have); 979 debug2("channel %d: pre_dynamic: have %d", c->self, have);
979 /* buffer_dump(&c->input); */ 980 /* buffer_dump(&c->input); */
980 /* check if the fixed size part of the packet is in buffer. */ 981 /* check if the fixed size part of the packet is in buffer. */
@@ -1133,11 +1134,18 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
1133 "to %.100s port %d requested.", 1134 "to %.100s port %d requested.",
1134 c->listening_port, c->path, c->host_port); 1135 c->listening_port, c->path, c->host_port);
1135 1136
1136 rtype = (c->type == SSH_CHANNEL_RPORT_LISTENER) ? 1137 if (c->type == SSH_CHANNEL_RPORT_LISTENER) {
1137 "forwarded-tcpip" : "direct-tcpip"; 1138 nextstate = SSH_CHANNEL_OPENING;
1138 nextstate = (c->host_port == 0 && 1139 rtype = "forwarded-tcpip";
1139 c->type != SSH_CHANNEL_RPORT_LISTENER) ? 1140 } else {
1140 SSH_CHANNEL_DYNAMIC : SSH_CHANNEL_OPENING; 1141 if (c->host_port == 0) {
1142 nextstate = SSH_CHANNEL_DYNAMIC;
1143 rtype = "direct-tcpip";
1144 } else {
1145 nextstate = SSH_CHANNEL_OPENING;
1146 rtype = "direct-tcpip";
1147 }
1148 }
1141 1149
1142 addrlen = sizeof(addr); 1150 addrlen = sizeof(addr);
1143 newsock = accept(c->sock, &addr, &addrlen); 1151 newsock = accept(c->sock, &addr, &addrlen);
@@ -1158,8 +1166,16 @@ channel_post_port_listener(Channel *c, fd_set * readset, fd_set * writeset)
1158 nc->host_port = c->host_port; 1166 nc->host_port = c->host_port;
1159 strlcpy(nc->path, c->path, sizeof(nc->path)); 1167 strlcpy(nc->path, c->path, sizeof(nc->path));
1160 1168
1161 if (nextstate != SSH_CHANNEL_DYNAMIC) 1169 if (nextstate == SSH_CHANNEL_DYNAMIC) {
1170 /*
1171 * do not call the channel_post handler until
1172 * this flag has been reset by a pre-handler.
1173 * otherwise the FD_ISSET calls might overflow
1174 */
1175 nc->delayed = 1;
1176 } else {
1162 port_open_helper(nc, rtype); 1177 port_open_helper(nc, rtype);
1178 }
1163 } 1179 }
1164} 1180}
1165 1181
@@ -1409,6 +1425,8 @@ channel_check_window(Channel *c)
1409static void 1425static void
1410channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset) 1426channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset)
1411{ 1427{
1428 if (c->delayed)
1429 return;
1412 channel_handle_rfd(c, readset, writeset); 1430 channel_handle_rfd(c, readset, writeset);
1413 channel_handle_wfd(c, readset, writeset); 1431 channel_handle_wfd(c, readset, writeset);
1414} 1432}
@@ -1416,6 +1434,8 @@ channel_post_open_1(Channel *c, fd_set * readset, fd_set * writeset)
1416static void 1434static void
1417channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset) 1435channel_post_open_2(Channel *c, fd_set * readset, fd_set * writeset)
1418{ 1436{
1437 if (c->delayed)
1438 return;
1419 channel_handle_rfd(c, readset, writeset); 1439 channel_handle_rfd(c, readset, writeset);
1420 channel_handle_wfd(c, readset, writeset); 1440 channel_handle_wfd(c, readset, writeset);
1421 channel_handle_efd(c, readset, writeset); 1441 channel_handle_efd(c, readset, writeset);