Skip Menu |

This queue is for tickets about the Net-SFTP CPAN distribution.

Report information
The Basics
Id: 14405
Status: resolved
Priority: 0/
Queue: Net-SFTP

People
Owner: Nobody in particular
Requestors: jim1138 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.09
Fixed in: (no value)



Subject: incorrect handling of $handle from SSH2_FXP_OPEN
Error found in Net/SFTP.pm revision 1.30 in subroutine put / line 449 We are connecting to a lame windows sftp server with returns "0" as a handle in response to SSH2_FXP_OPEN. Unfortunately, while this is a valid arbitrary string, its also false causing 0 length files to be created on the server. original: my $handle = $sftp->do_open($remote, SSH2_FXF_WRITE | SSH2_FXF_CREAT | SSH2_FXF_TRUNC, $a) or return; # check status for info fixed: my $handle = $sftp->do_open($remote, SSH2_FXF_WRITE | SSH2_FXF_CREAT | SSH2_FXF_TRUNC, $a); return unless defined $handle; # check status for info Thanks for an otherwise great module! Jim Herring
From: Jim Herring
There were several other instances of this bug in the module. Attached is a patch file that fixes all 3 calls to do_open or do_opendir. JMH
--- SFTP.pm 2005-10-03 15:51:34.000000000 -0400 +++ SFTP-jmh.pm 2005-10-03 15:55:43.000000000 -0400 @@ -382,7 +382,8 @@ my $want = defined wantarray ? 1 : 0; my $a = $sftp->do_stat($remote) or return; - my $handle = $sftp->do_open($remote, SSH2_FXF_READ) or return; + my $handle = $sftp->do_open($remote, SSH2_FXF_READ); + return unless defined $handle; local *FH; if ($local) { @@ -447,7 +448,8 @@ binmode FH or croak "Can't binmode FH: $!"; my $handle = $sftp->do_open($remote, SSH2_FXF_WRITE | SSH2_FXF_CREAT | - SSH2_FXF_TRUNC, $a) or return; # check status for info + SSH2_FXF_TRUNC, $a); # check status for info + return unless defined $handle; my $offset = 0; while (1) { @@ -477,7 +479,9 @@ my $sftp = shift; my($remote, $code) = @_; my @dir; - my $handle = $sftp->do_opendir($remote) or return; + my $handle = $sftp->do_opendir($remote); + return unless $handle; + while (1) { my $expected_id = $sftp->_send_str_request(SSH2_FXP_READDIR, $handle); my $msg = $sftp->get_msg;