Subject: Re: [libssh2] #257: [PATCH] libssh2_session_free: infinite loop

Re: [libssh2] #257: [PATCH] libssh2_session_free: infinite loop

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Thu, 05 Sep 2013 18:19:38 -0000

#257: [PATCH] libssh2_session_free: infinite loop
-----------------------+-------------------
  Reporter: greg2001 | Owner:
      Type: defect | Status: new
  Priority: normal | Milestone: 1.4.3
 Component: API | Version: 1.4.2
Resolution: | Keywords:
Blocked By: | Blocks:
-----------------------+-------------------

Comment (by bagder):

 On second thought, I think we can leave the loop if we fix so that the
 function removes the entrt from session->listeners also on errors. My
 suggested fix is thus:

 {{{
 diff --git a/src/channel.c b/src/channel.c
 index 71f2537..faff11e 100644
 --- a/src/channel.c
 +++ b/src/channel.c
 @@ -606,6 +606,7 @@ int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER
 *listen
      size_t packet_len =
          host_len + 14 + sizeof("cancel-tcpip-forward") - 1;
      int rc;
 + int retcode = 0;

      if (listener->chanFwdCncl_state == libssh2_NB_state_idle) {
          _libssh2_debug(session, LIBSSH2_TRACE_CONN,
 @@ -644,9 +645,11 @@ int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER
 *liste
              _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
                             "Unable to send global-request packet for
 forward "
                             "listen request");
 - LIBSSH2_FREE(session, packet);
 - listener->chanFwdCncl_state = libssh2_NB_state_idle;
 - return LIBSSH2_ERROR_SOCKET_SEND;
 + /* set the state to something we don't check for, for the
 + unfortunate situation where we get an EAGAIN further down
 + when trying to bail out due to errors! */
 + listener->chanFwdCncl_state = libssh2_NB_state_sent;
 + retcode = LIBSSH2_ERROR_SOCKET_SEND;
          }
          LIBSSH2_FREE(session, packet);

 @@ -670,7 +673,7 @@ int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER
 *listen

      LIBSSH2_FREE(session, listener);

 - return 0;
 + return retcode;
  }

 }}}

-- 
Ticket URL: <https://trac.libssh2.org/ticket/257#comment:4>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-09-05