comparison common-channel.c @ 243:0056419cf0f4

* ensure that we only handle open confirmation/failure for channels where it is expected
author Matt Johnston <matt@ucc.asn.au>
date Mon, 05 Sep 2005 17:10:32 +0000
parents c5d3ef11155f
children 84925eceeb13
comparison
equal deleted inserted replaced
242:3311f4aa52cb 243:0056419cf0f4
145 newchan->typedata = NULL; 145 newchan->typedata = NULL;
146 newchan->infd = FD_UNINIT; 146 newchan->infd = FD_UNINIT;
147 newchan->outfd = FD_UNINIT; 147 newchan->outfd = FD_UNINIT;
148 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */ 148 newchan->errfd = FD_CLOSED; /* this isn't always set to start with */
149 newchan->initconn = 0; 149 newchan->initconn = 0;
150 newchan->await_open = 0;
150 151
151 newchan->writebuf = cbuf_new(RECV_MAXWINDOW); 152 newchan->writebuf = cbuf_new(RECV_MAXWINDOW);
152 newchan->extrabuf = NULL; /* The user code can set it up */ 153 newchan->extrabuf = NULL; /* The user code can set it up */
153 newchan->recvwindow = RECV_MAXWINDOW; 154 newchan->recvwindow = RECV_MAXWINDOW;
154 newchan->recvdonelen = 0; 155 newchan->recvdonelen = 0;
931 setnonblocking(fd); 932 setnonblocking(fd);
932 933
933 chan->infd = chan->outfd = fd; 934 chan->infd = chan->outfd = fd;
934 ses.maxfd = MAX(ses.maxfd, fd); 935 ses.maxfd = MAX(ses.maxfd, fd);
935 936
937 chan->await_open = 1;
938
936 /* now open the channel connection */ 939 /* now open the channel connection */
937 CHECKCLEARTOWRITE(); 940 CHECKCLEARTOWRITE();
938 941
939 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN); 942 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_OPEN);
940 buf_putstring(ses.writepayload, type->name, strlen(type->name)); 943 buf_putstring(ses.writepayload, type->name, strlen(type->name));
957 960
958 channel = getchannel(); 961 channel = getchannel();
959 if (channel == NULL) { 962 if (channel == NULL) {
960 dropbear_exit("Unknown channel"); 963 dropbear_exit("Unknown channel");
961 } 964 }
965
966 if (!channel->await_open) {
967 dropbear_exit("unexpected channel reply");
968 }
969 channel->await_open = 0;
962 970
963 channel->remotechan = buf_getint(ses.payload); 971 channel->remotechan = buf_getint(ses.payload);
964 channel->transwindow = buf_getint(ses.payload); 972 channel->transwindow = buf_getint(ses.payload);
965 channel->transmaxpacket = buf_getint(ses.payload); 973 channel->transmaxpacket = buf_getint(ses.payload);
966 974
987 995
988 channel = getchannel(); 996 channel = getchannel();
989 if (channel == NULL) { 997 if (channel == NULL) {
990 dropbear_exit("Unknown channel"); 998 dropbear_exit("Unknown channel");
991 } 999 }
1000
1001 if (!channel->await_open) {
1002 dropbear_exit("unexpected channel reply");
1003 }
1004 channel->await_open = 0;
992 1005
993 removechannel(channel); 1006 removechannel(channel);
994 } 1007 }
995 #endif /* USING_LISTENERS */ 1008 #endif /* USING_LISTENERS */
996 1009