briandfoy / net-ssh-perl

Development on the Net::SSH::Perl module to support latest ciphers, key exchange mechanisms, etc.
Other
4 stars 1 forks source link

Width/height swapped in interactive shells. #42

Open briandfoy opened 1 year ago

briandfoy commented 1 year ago

This ticket was imported from rt.cpan.org 83978


This seems related to bug 60859, which is marked resolved, but the problem is still present in 1.35. This happens with both my distro- supplied perl 5.10.1 and a built-for-testing 5.16.3, on CentOS 6.3.

When requesting a pty, it's submitting the terminal width and height in the wrong order, in both the SSH2.pm and SSH1.pm files. It needs to send width, height, xpix, ypix; but, each time, it's sending height, width, xpix, ypix.

            if (defined $sz[0]) {
                    $foundsize = 1;
->                  $packet->put_int32($sz[1]); # height
->                  $packet->put_int32($sz[0]); # width
                    $packet->put_int32($sz[2]); # xpix
                    $packet->put_int32($sz[3]); # ypix
            }

I've attached patches for both SSH2.pm and SSH1.pm.

Example of buggy behavior:

  [sld@sandbox]~/work/% cat w
  #!/home/sld/localperl/bin/perl

  use strict;
  use warnings;
  use Net::SSH::Perl;
  use Term::ReadKey;

  my $ssh = Net::SSH::Perl->new("localhost",protocol=>2,interactive=>0);
  $ssh->login("other","somestring");
  ReadMode('raw');
  $ssh->shell;
  ReadMode('restore');

  [sld@sandbox]~/work/% stty size
  48 161
  [sld@sandbox]~/work/% ./w
  Last login: Thu Mar 14 13:52:20 2013 from localhost
  [other@sandbox ~]$ stty size
  161 48
  [other@sandbox ~]$ exit
  logout
  [sld@sandbox]~/work/% stty size
  48 161

After fixing SSH2.pm like this,

            if (defined $sz[0]) {
                $foundsize = 1;
->              $r_packet->put_int32($sz[0]); # width
->              $r_packet->put_int32($sz[1]); # height
                $r_packet->put_int32($sz[2]); # xpix
                $r_packet->put_int32($sz[3]); # ypix
            }

it then works as expected:

[sld@sandbox]~/work/% stty size
  48 161
  [sld@sandbox]~/work/% ./w
  Last login: Thu Mar 14 13:54:06 2013 from localhost
  [other@sandbox ~]$ stty size
  48 161
  [other@sandbox ~]$ exit
  logout
  [sld@sandbox]~/work/% stty size
  48 161

cheers, --sabrina