Subject: [libssh2] infinite loop in libssh2_channel_read_ex()? -- proposed mod

[libssh2] infinite loop in libssh2_channel_read_ex()? -- proposed mod

From: Bill Schell <friedfish_at_optonline.net>
Date: Tue, 30 Jan 2007 11:54:42 -0500

Hi. I just discovered that one of my applications that uses libssh2
(version 0.14) for SFTP was sitting in an infinite loop at 100% CPU
utilization. I pointed gdb at it and discovered that it was spinning in
libssh2_channel_read_ex(). This routine keeps calling
libssh2_packet_read(), which is returning 0 in the first 'if' statement
since the session->socket_state == LIBSSH2_SOCKET_DISCONNECTED.

It then falls down to the 'while' at line 937:

} while (channel->blocking && (bytes_read == 0) && !channel->remote.close);

which just causes the routine to go back and do the same thing again,
forever.

It looks like the statement at line 711 of packet.c in routine
libssh2_packet_read():

if (session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) { return 0 };
should be:
if (session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) { return -1; }

so that the above while loop will fall through and do the right thing.
 
Can somebody check me out on this? I'm not at all familiar with
libssh2 (I'm using it
for SFTP via the perl module Net::SFTP).

Thanks,
   Bill Schell

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-01-30