Subject: | Found 3 errors Net::TFTPd v0.03 - PATCH INCLUDED! |
Date: | Wed, 20 May 2009 17:47:01 +0000 (UTC) |
To: | bug-Net-TFTPd [...] rt.cpan.org |
From: | mjvincent [...] comcast.net |
I'm using Net::TFTPd version 0.03 on ActiveState Perl on Windows XP (SP3).
{C} > perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 12 registered patches, see perl -V for more detail)
Copyright 1987-2007, Larry Wall
Binary build 824 [287188] provided by ActiveState http://www.ActiveState.com
Built Sep 3 2008 11:14:55
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/ , the Perl Home Page.
1) When using a TFTP client to a simple TFTP server example I wrote based on the Pod documentation in Net::TFTPd, I get errors that the TFTP transfer mode is not supported (NetASCII). This was a simple fix in the TFTPd.pm file (included in the following 'diff -u' patch).
2) Next was a transfer issue when using NetASCII. It seems that the read call is not reading the file correctly and thus the transfer completes, but with an error. To demonstrate this, start the Pod sample TFTPd server and use Windows TFTP client to transfer a text file placed in the TFTP root directory.
C:> tftp localhost get testfile.txt
The error from the TFTPd Pod sample server is:
Error processing TFTP request: %sSocket RECV error:
I've added some carefully placed debug print statements to isolate the error and found that the file size (-s) calculated in the openFILE sub is correct; however, the actual file transfer is for less bytes. This seems to be due to the "read" in readFILE sub. I corrected the issue by changing 'read' to 'sysread'. Again, this is included in the following patch.
3) Finally, the error message reported was not very clear. The sendERR routine is set up to do it, but the error text is never included. For example, the sub should be called with ($code, $message) but $message is never included in any of the sendERR calls. Not a problem; we can just fill the $errmsg in the sub with the from the ERRORS has from the code sent to it. Again, this is included in the following patch.
Patch follows:
----------<CLIP HERE>----------
--- TFTPd.pm Mon Sep 17 01:51:07 2007
+++ TFTPd.pm Wed May 20 10:04:39 2009
@@ -248,7 +248,7 @@
if(defined($self->newSOCK()))
{
- if($self->{'_REQUEST_'}{'Mode'} ne 'OCTET')
+ if(($self->{'_REQUEST_'}{'Mode'} ne 'OCTET') && ($self->{'_REQUEST_'}{'Mode'} ne 'NETASCII'))
{
#request is not OCTET
$LASTERROR = sprintf "%s transfer mode is not supported\n", $self->{'_REQUEST_'}{'Mode'};
@@ -554,7 +554,7 @@
{
# if requested block is next block, read next block and return bytes read
my $fh = $self->{'_REQUEST_'}{'_FH_'};
- my $bytes = read($fh, $$datablk, $self->{'BlkSize'});
+ my $bytes = sysread($fh, $$datablk, $self->{'BlkSize'});
if(defined($bytes))
{
return($bytes);
@@ -1078,7 +1078,7 @@
{
my $self = shift;
my($errcode, $errmsg) = @_;
- $errmsg or $errmsg = '';
+ $errmsg or $errmsg = $ERRORS{$errcode};
my $udpserver = $self->{'_UDPSERVER_'};
----------<CLIP HERE>----------