comparison common-channel.c @ 365:49fcc9875045 channel-fix

Remove accidentally removed block (making sure to close the channel). Other minor cleanups.
author Matt Johnston <matt@ucc.asn.au>
date Wed, 11 Oct 2006 14:44:00 +0000
parents 90cb290836de
children 8d149b812669
comparison
equal deleted inserted replaced
364:90cb290836de 365:49fcc9875045
283 if (channel->recv_eof && !write_pending(channel)) { 283 if (channel->recv_eof && !write_pending(channel)) {
284 close_chan_fd(channel, channel->writefd, SHUT_WR); 284 close_chan_fd(channel, channel->writefd, SHUT_WR);
285 } 285 }
286 286
287 if (!channel->sent_eof 287 if (!channel->sent_eof
288 && channel->readfd == FD_CLOSED 288 && channel->readfd == FD_CLOSED
289 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) { 289 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) {
290 send_msg_channel_eof(channel); 290 send_msg_channel_eof(channel);
291 } 291 }
292
293 if (!channel->sent_close
294 && channel->writefd == FD_CLOSED
295 && channel->readfd == FD_CLOSED
296 && (channel->extrabuf != NULL || channel->errfd == FD_CLOSED)) {
297 send_msg_channel_close(channel);
298 }
299
292 } 300 }
293 301
294 302
295 /* Check whether a deferred (EINPROGRESS) connect() was successful, and 303 /* Check whether a deferred (EINPROGRESS) connect() was successful, and
296 * if so, set up the channel properly. Otherwise, the channel is cleaned up, so 304 * if so, set up the channel properly. Otherwise, the channel is cleaned up, so
333 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE); 341 buf_putbyte(ses.writepayload, SSH_MSG_CHANNEL_CLOSE);
334 buf_putint(ses.writepayload, channel->remotechan); 342 buf_putint(ses.writepayload, channel->remotechan);
335 343
336 encrypt_packet(); 344 encrypt_packet();
337 345
338 /* XXX is setting sent_eof required? */
339 channel->sent_eof = 1; 346 channel->sent_eof = 1;
340 channel->sent_close = 1; 347 channel->sent_close = 1;
341 TRACE(("leave send_msg_channel_close")) 348 TRACE(("leave send_msg_channel_close"))
342 } 349 }
343 350
467 474
468 TRACE(("enter recv_msg_channel_close")) 475 TRACE(("enter recv_msg_channel_close"))
469 476
470 channel = getchannel_msg("Close"); 477 channel = getchannel_msg("Close");
471 478
472 /* XXX eof required? */
473 channel->recv_eof = 1; 479 channel->recv_eof = 1;
474 channel->recv_close = 1; 480 channel->recv_close = 1;
475 481
476 check_close(channel); 482 check_close(channel);
477 TRACE(("leave recv_msg_channel_close")) 483 TRACE(("leave recv_msg_channel_close"))
481 * channel close */ 487 * channel close */
482 static void remove_channel(struct Channel * channel) { 488 static void remove_channel(struct Channel * channel) {
483 489
484 TRACE(("enter remove_channel")) 490 TRACE(("enter remove_channel"))
485 TRACE(("channel index is %d", channel->index)) 491 TRACE(("channel index is %d", channel->index))
486
487 /* XXX shuold we assert for sent_closed and recv_closed?
488 * but we also cleanup manually, maybe we need a flag. */
489 492
490 cbuf_free(channel->writebuf); 493 cbuf_free(channel->writebuf);
491 channel->writebuf = NULL; 494 channel->writebuf = NULL;
492 495
493 if (channel->extrabuf) { 496 if (channel->extrabuf) {
628 631
629 if (channel->recv_eof) { 632 if (channel->recv_eof) {
630 dropbear_exit("received data after eof"); 633 dropbear_exit("received data after eof");
631 } 634 }
632 635
633 /* XXX this is getting hit by people - maybe should be
634 * made less fatal (or just fixed).
635 *
636 * The most likely explanation is that the socket is being closed (due to
637 * write failure etc) but the far end doesn't know yet, so keeps sending
638 * packets. We already know that the channel number that was given was
639 * valid, so probably should skip out here. Maybe
640 * assert(channel->sent_close), thuogh only if the close-on-failure code is
641 * doing that */
642 if (fd < 0) { 636 if (fd < 0) {
643 dropbear_exit("received data with bad writefd"); 637 /* If we have encountered failed write, the far side might still
638 * be sending data without having yet received our close notification.
639 * We just drop the data. */
640 return;
644 } 641 }
645 642
646 datalen = buf_getint(ses.payload); 643 datalen = buf_getint(ses.payload);
647 644 TRACE(("length %d", datalen))
648 645
649 maxdata = cbuf_getavail(cbuf); 646 maxdata = cbuf_getavail(cbuf);
650 647
651 /* Whilst the spec says we "MAY ignore data past the end" this could 648 /* Whilst the spec says we "MAY ignore data past the end" this could
652 * lead to corrupted file transfers etc (chunks missed etc). It's better to 649 * lead to corrupted file transfers etc (chunks missed etc). It's better to