[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

0.5.5 Hang on sftp_new calling channel_open()


I have a Digi WR21 modem that if I attempt to make an sftp_new() call while
the modem is still booting I get a hang in channel_open() because the
channel->state never switches from SSH_CHANNEL_STATE_NOT_OPEN and there
isn't a check on the session timeout in:

  /* Todo: fix this into a correct loop */

  /* wait until channel is opened by server */

  while(channel->state == SSH_CHANNEL_STATE_NOT_OPEN){

    ssh_handle_packets(session,-1);

  }

 

So the the open call is stuck in that while loop without a way to break out.
Is there any reason why a check cant be added against the session->timeout
parameter like so:

 

static int channel_open(ssh_channel channel, const char *type_c, int window,

    int maxpacket, ssh_buffer payload) {

  ssh_session session = channel->session;

  ssh_string type = NULL;

  int err=SSH_ERROR;

  int useTimeout = (session->timeout + (1000 * session->timeout_usec)) > 0;

  time_t timeout = time(NULL) + session->timeout + (1000 *
session->timeout_usec);

 

  enter_function();

  channel->local_channel = ssh_channel_new_id(session);

  channel->local_maxpacket = maxpacket;

  channel->local_window = window;

 

  ssh_log(session, SSH_LOG_PROTOCOL,

      "Creating a channel %d with %d window and %d max packet",

      channel->local_channel, window, maxpacket);

 

  type = ssh_string_from_char(type_c);

  if (type == NULL) {

    ssh_set_error_oom(session);

    leave_function();

    return err;

  }

 

  if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_OPEN) < 0 ||

      buffer_add_ssh_string(session->out_buffer,type) < 0 ||

      buffer_add_u32(session->out_buffer, htonl(channel->local_channel)) < 0
||

      buffer_add_u32(session->out_buffer, htonl(channel->local_window)) < 0
||

      buffer_add_u32(session->out_buffer, htonl(channel->local_maxpacket)) <
0) {

    ssh_set_error_oom(session);

    ssh_string_free(type);

    leave_function();

    return err;

  }

 

  ssh_string_free(type);

 

  if (payload != NULL) {

    if (buffer_add_buffer(session->out_buffer, payload) < 0) {

      ssh_set_error_oom(session);

      leave_function();

      return err;

    }

  }

 

  if (packet_send(session) == SSH_ERROR) {

    leave_function();

    return err;

  }

 

  ssh_log(session, SSH_LOG_PACKET,

      "Sent a SSH_MSG_CHANNEL_OPEN type %s for channel %d",

      type_c, channel->local_channel);

 

  /* Todo: fix this into a correct loop */

  /* wait until channel is opened by server */

  while(channel->state == SSH_CHANNEL_STATE_NOT_OPEN && (!useTimeout ||
(useTimeout && (time(NULL) < timeout))) ){

    ssh_handle_packets(session,-1);

  }

  if(channel->state == SSH_CHANNEL_STATE_OPEN)

    err=SSH_OK;

  leave_function();

  return err;

}


Follow-Ups:
Re: 0.5.5 Hang on sftp_new calling channel_open()Andreas Schneider <asn@xxxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org