bug-wget
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-wget] [PATCH v6 2/5] Tests: fix TYPE and RETR command handling.


From: Yousong Zhou
Subject: [Bug-wget] [PATCH v6 2/5] Tests: fix TYPE and RETR command handling.
Date: Wed, 19 Mar 2014 23:42:05 +0800

 - FTPServer.pm's handling of TYPE command would ignore binary mode
   transfer request.
 - The FTP server would run into dead loop sending the same content
   forever.

Signed-off-by: Yousong Zhou <address@hidden>
---
 tests/ChangeLog    |    5 +++++
 tests/FTPServer.pm |   12 +++++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 6730169..a7db249 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2014-02-13  Yousong Zhou  <address@hidden>
+
+       * FTPServer.pm: Fix the handling of TYPE command and avoid endless
+       loop when doing binary mode RETR.
+
 2014-01-23  Lars Wendler  <address@hidden> (tiny change)
 
        * Test--post-file.px: Do not fail when wget has no debug support.
diff --git a/tests/FTPServer.pm b/tests/FTPServer.pm
index 2ac72e3..1603caa 100644
--- a/tests/FTPServer.pm
+++ b/tests/FTPServer.pm
@@ -298,12 +298,13 @@ sub _RETR_command
     # What mode are we sending this file in?
     unless ($conn->{type} eq 'A') # Binary type.
     {
-        my ($r, $buffer, $n, $w);
-
+        my ($r, $buffer, $n, $w, $sent);
 
         # Copy data.
-        while ($buffer = substr($content, 0, 65536))
+        $sent = 0;
+        while ($sent < length($content))
         {
+            $buffer = substr($content, $sent, 65536);
             $r = length $buffer;
 
             # Restart alarm clock timer.
@@ -330,6 +331,7 @@ sub _RETR_command
                 print {$conn->{socket}} "426 Transfer aborted. Data connection 
closed.\r\n";
                 return;
             }
+            $sent += $r;
         }
 
         # Cleanup and exit if there was an error.
@@ -410,9 +412,9 @@ sub _TYPE_command
 
     # See RFC 959 section 5.3.2.
     if ($type =~ /^([AI])$/i) {
-        $conn->{type} = 'A';
+        $conn->{type} = $1;
     } elsif ($type =~ /^([AI])\sN$/i) {
-        $conn->{type} = 'A';
+        $conn->{type} = $1;
     } elsif ($type =~ /^L\s8$/i) {
         $conn->{type} = 'L8';
     } else {
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]