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

Re: libssh and python twisted conch ssh


Hi Johannes,

That's a good idea. Please change your "r=1; while(r>0) {} loop in a do
{} while(r>0); loop, and I'll merge it in libssh.

Aris

Le 22/01/13 13:12, Johannes Krude a écrit :
> hi,
> 
> On Tue, Jan 22, 2013 at 10:57:22AM +0100, Aris Adamantiadis wrote:
>> I took a look at your pcap (next time please just attach it :)).
>> It seems like twisted sends the key exchange packet right away before
>> listening for the client's banner.
>> As the packet is already buffered, the packet parsing is never triggered
>> because it's waiting for socket input first.
> The following fixes this behavior by repeatedly calling the data handler as
> long as it takes data (https://git.aachen.ccc.de/~johannes/libssh/).
> 
> johannes
> 
> 
> diff --git a/src/socket.c b/src/socket.c
> index 6eab0aa..8569054 100644
> --- a/src/socket.c
> +++ b/src/socket.c
> @@ -283,12 +283,15 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r
>                  return -1;
>              }
>  			if(s->callbacks && s->callbacks->data){
> -				r= s->callbacks->data(buffer_get_rest(s->in_buffer),
> -						buffer_get_rest_len(s->in_buffer),
> -						s->callbacks->userdata);
> -				buffer_pass_bytes(s->in_buffer,r);
> -				/* p may have been freed, so don't use it
> -				* anymore in this function */
> +				r= 1;
> +				while (r > 0) {
> +					r= s->callbacks->data(buffer_get_rest(s->in_buffer),
> +							buffer_get_rest_len(s->in_buffer),
> +							s->callbacks->userdata);
> +					buffer_pass_bytes(s->in_buffer,r);
> +					/* p may have been freed, so don't use it
> +					* anymore in this function */
> +				}
>  				p = NULL;
>  			}
>  		}
> 
> 

Follow-Ups:
Re: libssh and python twisted conch sshJohannes Krude <johannes@xxxxxxxx>
References:
libssh and python twisted conch sshJohannes Krude <johannes@xxxxxxxx>
Re: libssh and python twisted conch sshAris Adamantiadis <aris@xxxxxxxxxxxx>
Re: libssh and python twisted conch sshJohannes Krude <johannes@xxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org