Skip Menu |

This queue is for tickets about the libnet CPAN distribution.

Report information
The Basics
Id: 20082
Status: resolved
Priority: 0/
Queue: libnet

People
Owner: Nobody in particular
Requestors: arak [...] cpan.org
Cc: dmo+pause [...] dmo.ca
AdminCc:

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



Subject: Broken STOU command (Net::FTP-2.75)
put_unique method in Net::FTP internally uses STOU command. Since put_unique is really just a wrapper for _store_cmd STOU command is issued with remote filename. Now, according to RFC959 STOU should be followed by <CLRF> (which makes sence since you ask the server to come up with remote filename). Net::FTP (2.75) line 759: $sock = $ftp->_data_cmd($cmd, $remote) or return undef; You might want to add conditional $remote parameter here. ... Net::FTP=GLOB(0x83ca9e0)>>> TYPE I Net::FTP=GLOB(0x83ca9e0)<<< 200 Type set to Image. Net::FTP=GLOB(0x83ca9e0)>>> PORT 127,0,0,1,16,168 Net::FTP=GLOB(0x83ca9e0)<<< 200 PORT command successful. Net::FTP=GLOB(0x83ca9e0)>>> STOU /tmp/7a958980e7f07e2dcb2cbc28ede00f9b Net::FTP=GLOB(0x83ca9e0)<<< 500 'STOU /tmp/7a958980e7f07e2dcb2cbc28ede00f9b': Syntax error, expecting <CRLF>.
Subject: [rt.cpan.org #20082] Broken STOU command (Net::FTP-2.75)
Date: Wed, 30 Jan 2008 15:47:48 -0500
To: bug-libnet [...] rt.cpan.org
From: Aidan Van Dyk <aidan [...] highrise.ca>
Here's a patch t fix it: --- /usr/share/perl/5.8.8/Net/FTP.pm 2007-11-07 19:41:40.000000000 -0500 +++ Net/FTP.pm 2008-01-30 15:38:45.000000000 -0500 @@ -701,6 +701,13 @@ sub stor { shift->_data_cmd("STOR",@_) } sub stou { shift->_data_cmd("STOU",@_) } sub appe { shift->_data_cmd("APPE",@_) } +sub _need_name +{ + my ($ftp, $cmd) = @_; + return undef if 'STOU' eq uc $cmd; + return 1; +} + sub _store_cmd { my($ftp,$cmd,$local,$remote) = @_; @@ -709,7 +716,7 @@ sub _store_cmd my $localfd = ref($local) || ref(\$local) eq "GLOB"; - unless(defined $remote) + if( (not defined $remote) && $ftp->_need_name($cmd) ) { croak 'Must specify remote filename with stream input' if $localfd; @@ -756,7 +763,10 @@ sub _store_cmd delete ${*$ftp}{'net_ftp_port'}; delete ${*$ftp}{'net_ftp_pasv'}; - $sock = $ftp->_data_cmd($cmd, $remote) or + my @args = ($cmd); + push @args, $remote if defined $remote; + + $sock = $ftp->_data_cmd(@args) or return undef; $remote = ($ftp->message =~ /FILE:\s*(.*)/)[0] -- Aidan Van Dyk Create like a god, aidan@highrise.ca command like a king, http://www.highrise.ca/ work like a slave.
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #20082] Broken STOU command (Net::FTP-2.75)
Date: Wed, 30 Jan 2008 18:50:39 -0600
To: bug-libnet [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 30, 2008, at 2:48 PM, Aidan Van Dyk via RT wrote: Show quoted text
> Here's a patch t fix it:
Nothing like being polite :-) It would help if you described what problem you had. $remote will default to the local name and is only required if send a stream and there is a check for that case. your patch could also result in a stor command being sent with no name. Graham. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (Darwin) iD8DBQFHoRtfR0BL4gbYw3QRAmwNAJwNC8LCUQA3ILRgkJLaMMvx7oolUwCfeFtC 4g+d3g6TSWiAi6qytpENXUE= =Ltu+ -----END PGP SIGNATURE-----
Subject: Re: [rt.cpan.org #20082] Broken STOU command (Net::FTP-2.75)
Date: Thu, 31 Jan 2008 00:17:40 -0500
To: bug-libnet [...] rt.cpan.org
From: "Dave O'Neill" <dmo [...] dmo.ca>
On Jan 30, 2008 at 18:50:39 -0600, Graham Barr wrote: Show quoted text
> On Jan 30, 2008, at 2:48 PM, Aidan Van Dyk via RT wrote:
> > Here's a patch t fix it:
> > Nothing like being polite :-) > > It would help if you described what problem you had.
He was replying to the original issue on RT #20082 -- Net::FTP doesn't appear to implement a fully RFC-compliant STOU. Based on the discussion I had with Aidan today, he seems to have independently discovered the problem described by the original reporter. The reason I'm jumping in here is because I'm the one who convinced Aidan that rather than sitting on a private patch that fixes this bug he should be nice and feed it back to the community, especially when it fixes an RFC-compliance issue that's been an open ticket (albeit a poorly explained one) for over a year. Show quoted text
> $remote will default to the local name and is only required if send a > stream and there is a check for that case.
According to RFC 959, STOU should never have a remote filename argument. The command should be STOU<CRLF> and shouldn't default to the local filename at all, as the server generates the filename and returns it. Here's the problem in detail. This is what you'd expect to do to send a STOU: my $local_filename = '/tmp/whatever'; $ftp->put_unique( $local_filename ) But, this will default $remote to the local filename, and send: "STOU /tmp/whatever\015\012" to the remote server. This will fail, because STOU doesn't take an argument. Since the code checks for undef, the obvious workaround is to try providing a blank remote filename: my $local_filename = '/tmp/whatever'; $ftp->put_unique( $local_filename, '' ) It does work around the default assignation of the local filename to $remote. Unfortunately, it does generate a broken command: "STOU \015\012" The trailing space after the STOU can cause some FTP servers to reject it as invalid. Show quoted text
> your patch could also result in a stor command being sent with no name.
It shouldn't do so -- $ftp->_need_name($cmd) will only return a false value iff $cmd is STOU, so the $remote name should always default to the local one for a STOR. Please reopen the ticket and apply his patch for the next release. Thanks, Dave
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #20082] Broken STOU command (Net::FTP-2.75)
Date: Thu, 31 Jan 2008 11:50:16 -0500
To: bug-libnet [...] rt.cpan.org
From: Aidan Van Dyk <aidan [...] highrise.ca>
Sorry for the "no context" patch.. I did put it on the ticket, to try give some context. Dave's right. Basically, the patch allows the $remote to be optional, based on the _need_name result. Can I be added as a CC to the ticket? -- Aidan Van Dyk Create like a god, aidan@highrise.ca command like a king, http://www.highrise.ca/ work like a slave.
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #20082] Broken STOU command (Net::FTP-2.75)
Date: Fri, 1 Feb 2008 14:02:45 -0500
To: bug-libnet [...] rt.cpan.org
From: Aidan Van Dyk <aidan [...] highrise.ca>
Any update? -- Aidan Van Dyk Create like a god, aidan@highrise.ca command like a king, http://www.highrise.ca/ work like a slave.
Download signature.asc
application/pgp-signature 189b

Message body not shown because it is not plain text.

This has been fixed in the repository See http://svn.goingon.net/viewvc/libnet/trunk/Net/FTP.pm?r1=332&r2=339 Graham.