Subject: Re: [libssh2] libssh2-0.17 infinite recv() loop at startup

Re: [libssh2] libssh2-0.17 infinite recv() loop at startup

From: Satish Mittal <satish.mittal_at_gmail.com>
Date: Wed, 8 Aug 2007 17:06:21 +0530

Hi All,

I have been using libssh2-0.14 for the past 10 months now (since last
october) in my application, and dealing with its various bugs, making it
compile/work on Windows and all major *nix platforms.

One of the most serious bug we have encountered is the one mentioned below.
It leads to an infinite loop in the library. In a scenario where there are
multiple threads trying to make their own connections, this simply means CPU
usage getting launched, and the calling application hangs.

I had earlier reported this issue on this mailing list. I am surprised this
is still persisting till 0.17. We should quickly fix it now.

The fix I have tried is:
-- if (ret == 0) continue;
++ if (ret == 0)
{
            session->socket_state = LIBSSH2_SOCKET_DISCONNECTED;
            return -1;
}

This bug is present at 2 places:

a) in session.c during the banner exchange, as mentioned below.
b) in packet.c inside libssh2_blocking_read() again we have a continue when
ret == 0.

Regards,
Satish

On 8/8/07, Sullivan, David J. <djms_at_bear.com> wrote:
>
> In src/session.c, libssh2_session_startup() sets the session socket to
> blocking mode, calls libssh2_banner_send() then calls
> libssh2_banner_receive().
>
> If the connection is dropped by the client between those two calls,
> libssh2_banner_receive() hard loops doing recv()'s that are returning 0.
>
> The culprit seems to be the "if (ret <= 0) continue;" code. Placing the
> continue in the loop above (which is "if (ret < 0 )") and adding code to
> check for zero seems to do the trick:
>
> } else {
> /* Some kinda error */
> session->banner_TxRx_state = libssh2_NB_state_idle;
> session->banner_TxRx_total_send = 0;
> return 1;
> }
> continue;
> }
>
> if (ret == 0) {
> /* EOF */
> session->banner_TxRx_state = libssh2_NB_state_idle;
> session->banner_TxRx_total_send = 0;
> return 1;
> }
>
> David
>
>
>
>
> ***********************************************************************
> Bear Stearns is not responsible for any recommendation, solicitation,
> offer or agreement or any information about any transaction, customer
> account or account activity contained in this communication.
> ***********************************************************************
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> libssh2-devel mailing list
> libssh2-devel_at_lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libssh2-devel
>

-- 
"The happiest of people donĀ“t necessarily have the best of everything, they
just make the most of everything that comes along their way."

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-08-08