From: wessels <> Date: Sat, 5 May 2007 05:46:42 +0000 (+0000) Subject: Fixed "spec->length >= 0" assertion for FTP request with range X-Git-Tag: SQUID_3_0_PRE6~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=690b22c63e7955fd3ff00ca8afd2950c2f35b790;p=thirdparty%2Fsquid.git Fixed "spec->length >= 0" assertion for FTP request with range 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. --- diff --git a/src/ftp.cc b/src/ftp.cc index 6305f567ec..cce5f20887 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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 */