]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 432: http_reply_body_max_size fails with ident acls
authorhno <>
Sun, 11 May 2003 19:53:03 +0000 (19:53 +0000)
committerhno <>
Sun, 11 May 2003 19:53:03 +0000 (19:53 +0000)
src/HttpReply.cc
src/HttpReply.h
src/client_side_reply.cc
src/client_side_reply.h
src/client_side_request.cc
src/client_side_request.h
src/structs.h

index b15f3680833b843200612699fe2e4a9566ee1fe5..6f5a691b3514d98eb81aaf9f70a5a48020e4a4a0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpReply.cc,v 1.59 2003/03/15 04:17:38 robertc Exp $
+ * $Id: HttpReply.cc,v 1.60 2003/05/11 13:53:03 hno Exp $
  *
  * DEBUG: section 58    HTTP Reply (Response)
  * AUTHOR: Alex Rousskov
@@ -94,7 +94,6 @@ httpReplyInit(HttpReply * rep)
 {
     assert(rep);
     rep->hdr_sz = 0;
-    rep->maxBodySize = 0;
     rep->pstate = psReadyToParseStartLine;
     httpBodyInit(&rep->body);
     httpHeaderInit(&rep->header, hoReply);
@@ -600,34 +599,6 @@ httpReplyBodySize(method_t method, HttpReply const * reply)
     return reply->content_length;
 }
 
-/*
- * Calculates the maximum size allowed for an HTTP response
- */
-void
-httpReplyBodyBuildSize(request_t * request, HttpReply * reply, dlink_list * bodylist)
-{
-    body_size *bs;
-    ACLChecklist *checklist;
-    bs = (body_size *) bodylist->head;
-
-    while (bs) {
-        checklist = aclChecklistCreate(bs->access_list, request, NULL);
-        checklist->reply = reply;
-
-        if (1 != aclCheckFast(bs->access_list, checklist)) {
-            /* deny - skip this entry */
-            bs = (body_size *) bs->node.next;
-        } else {
-            /* Allow - use this entry */
-            reply->maxBodySize = bs->maxsize;
-            bs = NULL;
-            debug(58, 3) ("httpReplyBodyBuildSize: Setting maxBodySize to %ld\n", (long int) reply->maxBodySize);
-        }
-
-        delete checklist;
-    }
-}
-
 MemPool *HttpReply::Pool(NULL);
 void *
 HttpReply::operator new (size_t byteCount)
@@ -646,15 +617,3 @@ HttpReply::operator delete (void *address)
 {
     memPoolFree (Pool, address);
 }
-
-bool
-HttpReply::isBodyTooLarge(ssize_t clen) const
-{
-    if (0 == maxBodySize)
-        return 0;              /* disabled */
-
-    if (clen < 0)
-        return 0;              /* unknown */
-
-    return (unsigned int)clen > maxBodySize;
-}
index 6aaac79f1209c97c29230ffe8c5423038ddad7a9..e43671484e51bcb9c88cc053346b6b436eb5210a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpReply.h,v 1.2 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpReply.h,v 1.3 2003/05/11 13:53:03 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -73,7 +73,6 @@ extern time_t httpReplyExpires(const HttpReply * rep);
 extern int httpReplyHasCc(const HttpReply * rep, http_hdr_cc_type type);
 extern void httpRedirectReply(HttpReply *, http_status, const char *);
 extern int httpReplyBodySize(method_t, HttpReply const *);
-extern void httpReplyBodyBuildSize(request_t *, HttpReply *, dlink_list *);
 extern int httpReplyValidatorsMatch (HttpReply const *, HttpReply const *);
 
 #endif /* SQUID_HTTPREPLY_H */
index e44c5c3ff6dcd99e9efd71f6121ca5c1e19c5c15..8bd31f9c56519561b8351623d464468e2cca2d52 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_reply.cc,v 1.49 2003/04/20 05:28:58 robertc Exp $
+ * $Id: client_side_reply.cc,v 1.50 2003/05/11 13:53:03 hno Exp $
  *
  * DEBUG: section 88    Client-side Reply Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -1216,7 +1216,8 @@ clientReplyContext::replyStatus()
         return STREAM_UNPLANNED_COMPLETE;
     }
 
-    if (http->entry->getReply()->isBodyTooLarge(http->out.offset)) {
+    if (http->isReplyBodyTooLarge(http->out.offset - 4096)) {
+        /* 4096 is a margin for the HTTP headers included in out.offset */
         debug(88, 5) ("clientReplyStatus: client reply body is too large\n");
         return STREAM_FAILED;
     }
@@ -1463,6 +1464,7 @@ clientReplyContext::buildReply(const char *buf, size_t size)
             /* this will fail and destroy request->range */
             //          clientBuildRangeHeader(http, holdingReply);
         }
+
     }
 
     /* enforce 1.0 reply version */
@@ -1805,14 +1807,42 @@ clientReplyContext::holdReply(HttpReply *aReply)
     holdingReply = aReply;
 }
 
+/*
+ * Calculates the maximum size allowed for an HTTP response
+ */
+void
+clientReplyContext::buildMaxBodySize(HttpReply * reply)
+{
+    body_size *bs;
+    ACLChecklist *checklist;
+    bs = (body_size *) Config.ReplyBodySize.head;
+
+    while (bs) {
+        checklist = clientAclChecklistCreate(bs->access_list, http);
+        checklist->reply = reply;
+
+        if (1 != aclCheckFast(bs->access_list, checklist)) {
+            /* deny - skip this entry */
+            bs = (body_size *) bs->node.next;
+        } else {
+            /* Allow - use this entry */
+            http->maxReplyBodySize(bs->maxsize);
+            bs = NULL;
+            debug(58, 3) ("httpReplyBodyBuildSize: Setting maxBodySize to %ld\n", (long int) http->maxReplyBodySize());
+        }
+
+        delete checklist;
+    }
+}
+
 void
 clientReplyContext::processReplyAccess ()
 {
     HttpReply *rep = holdingReply;
     holdReply(NULL);
-    httpReplyBodyBuildSize(http->request, rep, &Config.ReplyBodySize);
+    buildMaxBodySize(rep);
 
-    if (rep->isBodyTooLarge(rep->content_length)) {
+    if (http->isReplyBodyTooLarge(rep->content_length)) {
         ErrorState *err =
             clientBuildError(ERR_TOO_BIG, HTTP_FORBIDDEN, NULL,
                              http->conn ? &http->conn->peer.sin_addr : &no_addr,
index cc610e006189c8eca696d7cd112bed00b1b58e4c..bc551fca488caff4f89e9bbb4b233d3bc253c95d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_reply.h,v 1.2 2003/04/06 08:23:10 robertc Exp $
+ * $Id: client_side_reply.h,v 1.3 2003/05/11 13:53:03 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -148,6 +148,8 @@ private:
     void handleIMSGiveClientUpdatedOldEntry();
     void handleIMSGiveClientNewEntry();
     void sendClientOldEntry();
+    void clientReplyContext::buildMaxBodySize(HttpReply * reply);
+
 
     StoreEntry *old_entry;
     store_client *old_sc;      /* ... for entry to be validated */
index ee4888c1285171a6ac6a87fcac2324c3ea1fed16..ea1cd3c586f9920d5a3dd2350aed7445093b9af8 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_request.cc,v 1.20 2003/03/15 04:17:39 robertc Exp $
+ * $Id: client_side_request.cc,v 1.21 2003/05/11 13:53:03 hno Exp $
  * 
  * DEBUG: section 85    Client-side Request Routines
  * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
@@ -877,3 +877,26 @@ ClientHttpRequest::gotEnough() const
     return true;
 }
 
+void
+ClientHttpRequest::maxReplyBodySize(ssize_t clen)
+{
+    maxReplyBodySize_ = clen;
+}
+
+ssize_t
+ClientHttpRequest::maxReplyBodySize() const
+{
+    return maxReplyBodySize_;
+}
+
+bool
+ClientHttpRequest::isReplyBodyTooLarge(ssize_t clen) const
+{
+    if (0 == maxReplyBodySize())
+        return 0;      /* disabled */
+
+    if (clen < 0)
+        return 0;      /* unknown */
+
+    return clen > maxReplyBodySize();
+}
index 62b0cbf922d140c16b3c24f53f1a7ef121448cd2..6621aef6716b9ef827733177da0d94cf7e4bbdf4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side_request.h,v 1.9 2003/03/15 04:17:39 robertc Exp $
+ * $Id: client_side_request.h,v 1.10 2003/05/11 13:53:03 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -123,7 +123,12 @@ unsigned int purging:
     dlink_list client_stream;
     int mRangeCLen();
 
+    ssize_t maxReplyBodySize() const;
+    void maxReplyBodySize(ssize_t size);
+    bool isReplyBodyTooLarge(ssize_t len) const;
+
 private:
+    ssize_t maxReplyBodySize_;
     CBDATA_CLASS(ClientHttpRequest);
 };
 
index 23d7b6b5167e152fc07130977cac3b7163f23cd6..fe3b92679ec2b471738b1ab89970dd94ceb2d27a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.461 2003/04/17 15:25:44 hno Exp $
+ * $Id: structs.h,v 1.462 2003/05/11 13:53:03 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -948,7 +948,6 @@ class HttpReply
 public:
     void *operator new (size_t);
     void operator delete (void *);
-    bool isBodyTooLarge(ssize_t clen) const;
     /* unsupported, writable, may disappear/change in the future */
     int hdr_sz;                        /* sums _stored_ status-line, headers, and <CRLF> */
 
@@ -970,7 +969,6 @@ public:
     HttpStatusLine sline;
     HttpHeader header;
     HttpBody body;             /* for small constant memory-resident text bodies only */
-    size_t maxBodySize;
 
 private:
     static MemPool *Pool;