]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed "spec->length >= 0" assertion for FTP request with range
authorwessels <>
Sat, 5 May 2007 05:46:42 +0000 (05:46 +0000)
committerwessels <>
Sat, 5 May 2007 05:46:42 +0000 (05:46 +0000)
An FTP request with range offset larger than the content length
would result in a negative spec->length.  With this patch
we detect the condition and return a 200, instead of 206, reply.

The reply may be bogus, depending on how the FTP server behaves.
For example, the reply may have non-zero content-length header,
but no actual content (because we told the FTP server to restart
beyond the content size).

A future patch will try to make sure that we don't send a restart
command beyond the known object size.

src/ftp.cc

index 6305f567ec0eeaadfdf0267ddc4d78b2c181d7a5..cce5f2088763f685e5d19e62a34fc7878cfed2ec 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.419 2007/04/30 16:56:09 wessels Exp $
+ * $Id: ftp.cc,v 1.420 2007/05/04 23:46:42 wessels Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -3162,20 +3162,29 @@ FtpStateData::appendSuccessHeader()
 
     /* set standard stuff */
 
-    if (restarted_offset) {
+    HttpVersion version(1, 0);
+    if (0 == restarted_offset) {
+        /* Full reply */
+        reply->setHeaders(version, HTTP_OK, "Gatewaying",
+                          mime_type, size, mdtm, -2);
+    } else if (size < restarted_offset) {
+       /*
+        * offset should not be larger than size.
+        */
+       debugs(0,0,HERE << "Whoops! " <<
+               " restarted_offset=" << restarted_offset <<
+               ", but size=" << size <<
+               ".  assuming full content response");
+        reply->setHeaders(version, HTTP_OK, "Gatewaying",
+                          mime_type, size, mdtm, -2);
+    } else {
         /* Partial reply */
         HttpHdrRangeSpec range_spec;
         range_spec.offset = restarted_offset;
         range_spec.length = size - restarted_offset;
-        HttpVersion version(1, 0);
         reply->setHeaders(version, HTTP_PARTIAL_CONTENT, "Gatewaying",
                           mime_type, size - restarted_offset, mdtm, -2);
         httpHeaderAddContRange(&reply->header, range_spec, size);
-    } else {
-        /* Full reply */
-        HttpVersion version(1, 0);
-        reply->setHeaders(version, HTTP_OK, "Gatewaying",
-                          mime_type, size, mdtm, -2);
     }
 
     /* additional info */