Net-SSH-Perl - Re: Bug in Channel.pm when stdin length is just right

Posted on Fri Jun 16 23:34:52 2006 by cmv in response to 1889 (See the whole thread of 6)
Re: Bug in Channel.pm when stdin length is just right
Folks-

Not only is this bug appearing on many different platforms, but the fix I proposed earlier (and the subsequent jgilbert fix) doesn't work on some of them with v1.30 (ppc-linux in particular).

I've written a perl script to cause the bug to occur, and identify just how many characters your system needs to trigger it. Can you try running it and see if you have the bug and post your results here? I've also sent this to Dave Robins to see if he can figure this but out once and for all.

Attached is my output.

Thanks
-Craig
#!/usr/bin/perl use strict; use warnings; use English; use Data::Dumper; # Set these for your remote host... my $user = "user"; my $password = "password"; my $host = "machine"; # Time to wait for remote command to finish... my $timeout=10; # Consider upping this if you change $high # Remote command... my $cmd = "cat"; # Print heading... print "Net::SSH::Perl bug test...\n"; print "host=$host user=$user remoteCmd=$cmd\n"; # Set variables... my $high=932779; # Maximum number of starting xmitChars my $low=0; my $i=$high; my $delta=$high-$low;; my $ssh; # Main loop... while($delta>1) { undef($ssh); print "xferChars=$i"; # setup SSH... $ssh = newssh() || die "Can't create a new ssh, exiting..."; print '|'; # Indicates newssh worked... $ssh->login($user,$password) || die "Can't login, exiting..."; print '-'; # Indicates successful login... # Proper values of $i will trigger the bug... my $stdin = '=' x $i; # Run remote command... my ($stdout, $stderr, $exit) = runcmd($ssh, $cmd, $stdin, $timeout); # Check output... if(defined($stdout)) { if(length($stdout) != $i) { die "Data mismatch, expected: $i chars, got: ", length($stdout), "chars\n"; } # Go back up... $delta = $high-$i; $low = $i; $i += int($delta/2); print "OK, back up to $i chars\n" }else{ # Go down... $delta = $i-$low; $high = $i; $i -= int($delta/2); print "Error, down to $i chars\n\t$stderr\n"; next; } } if ($i == $high) { print "\nBug did not trigger with $high chars on this system.\n"; }else{ print "\nReport for remote host: $host...\n"; print "xferChars=$low works, xferChars=$high hangs on timeout=$timeout.\n"; } print "exiting...\n"; sub newssh { my $ssh; # Require the correct SSH package, based on OS... if($OSNAME=~/^(MSWin32)/) { require Net::SSH::W32Perl; $ssh = Net::SSH::W32Perl->new( $host, port => 22 , protocol => 2, #debug => 999, ); }else{ require Net::SSH::Perl; $ssh = Net::SSH::Perl->new( $host, port => 22 , protocol => 2, #debug => 999, ); } return($ssh); } sub runcmd { my $ssh = shift || die "Missing ssh object"; my $cmd = shift || die "Missing cmd"; my $stdin = shift || die "Missing stdin"; my $timeout = shift || die "Missing timeout"; my ($stdout, $stderr, $exit); eval { local $SIG{'ALRM'} = sub { die "alarm handler $timeout second timeout"; }; alarm($timeout); ($stdout, $stderr, $exit) = $ssh->cmd($cmd, $stdin); alarm(0); }; if($@) { $stderr=$@; $stderr=~s/( at |\n).*$/ /s; } return ($stdout, $stderr, $exit); }
Here is my output:
Net::SSH::Perl bug test... host=nwsgpb user=watchmrk remoteCmd=cat xferChars=932779|-Error, down to 466390 chars Received disconnect message: Corrupted MAC on input. xferChars=466390|-Error, down to 233195 chars Received disconnect message: Corrupted MAC on input. xferChars=233195|-Error, down to 116598 chars Received disconnect message: Corrupted MAC on input. xferChars=116598|-Error, down to 58299 chars Received disconnect message: Corrupted MAC on input. xferChars=58299|-Error, down to 29150 chars alarm handler 10 second timeout xferChars=29150|-Error, down to 14575 chars alarm handler 10 second timeout xferChars=14575|-Error, down to 7288 chars alarm handler 10 second timeout xferChars=7288|-OK, back up to 10931 chars xferChars=10931|-OK, back up to 12753 chars xferChars=12753|-Error, down to 11842 chars alarm handler 10 second timeout xferChars=11842|-Error, down to 11387 chars alarm handler 10 second timeout xferChars=11387|-OK, back up to 11614 chars xferChars=11614|-Error, down to 11501 chars alarm handler 10 second timeout xferChars=11501|-OK, back up to 11557 chars xferChars=11557|-Error, down to 11529 chars Received disconnect message: Corrupted MAC on input. xferChars=11529|-OK, back up to 11543 chars xferChars=11543|-Error, down to 11536 chars Received disconnect message: Corrupted MAC on input. xferChars=11536|-Error, down to 11533 chars alarm handler 10 second timeout xferChars=11533|-OK, back up to 11534 chars xferChars=11534|-OK, back up to 11535 chars xferChars=11535|-OK, back up to 11535 chars Report for remote host: nwsgpb... xferChars=11535 works, xferChars=11536 hangs on timeout=10. exiting...
Direct Responses: 6967 | Write a response