]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
More review updates
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 23 Jan 2015 19:21:54 +0000 (11:21 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 23 Jan 2015 19:21:54 +0000 (11:21 -0800)
src/http/one/Parser.cc
src/http/one/Parser.h
src/http/one/RequestParser.cc
src/http/one/ResponseParser.cc

index e072d79a2bbd9437c5b8d397fbd43bc989fa790e..b5f9770811c7c777a464884112546b0c3eada4bc 100644 (file)
@@ -39,7 +39,7 @@ Http::One::Parser::skipLineTerminator(::Parser::Tokenizer &tok) const
 }
 
 bool
-Http::One::Parser::findMimeBlock(const char *which, const size_t limit)
+Http::One::Parser::grabMimeBlock(const char *which, const size_t limit)
 {
     // MIME headers block exist in (only) HTTP/1.x and ICY
     const bool expectMime = (msgProtocol_.protocol == AnyP::PROTO_HTTP && msgProtocol_.major == 1) ||
@@ -50,9 +50,22 @@ Http::One::Parser::findMimeBlock(const char *which, const size_t limit)
          *       So the rest of the code will need to deal with '0'-byte headers
          *       (ie, none, so don't try parsing em)
          */
-        int64_t mimeHeaderBytes = 0;
         // XXX: c_str() reallocates. performance regression.
-        if ((mimeHeaderBytes = headersEnd(buf_.c_str(), buf_.length())) == 0) {
+        if (int64_t mimeHeaderBytes = headersEnd(buf_.c_str(), buf_.length())) {
+
+            // Squid could handle these headers, but admin does not want to
+            if (firstLineSize() + mimeHeaderBytes >= limit) {
+                debugs(33, 5, "Too large " << which);
+                parseStatusCode = Http::scHeaderTooLarge;
+                buf_.consume(mimeHeaderBytes);
+                parsingStage_ = HTTP_PARSE_DONE;
+                return false;
+            }
+
+            mimeHeaderBlock_ = buf_.consume(mimeHeaderBytes);
+            debugs(74, 5, "mime header (0-" << mimeHeaderBytes << ") {" << mimeHeaderBlock_ << "}");
+
+        } else { // headersEnd() == 0
             if (buf_.length()+firstLineSize() >= limit) {
                 debugs(33, 5, "Too large " << which);
                 parseStatusCode = Http::scHeaderTooLarge;
@@ -62,17 +75,6 @@ Http::One::Parser::findMimeBlock(const char *which, const size_t limit)
             return false;
         }
 
-        // Squid could handle these headers, but admin does not want to
-        if (messageHeaderSize() >= limit) {
-            debugs(33, 5, "Too large " << which);
-            parseStatusCode = Http::scHeaderTooLarge;
-            parsingStage_ = HTTP_PARSE_DONE;
-            return false;
-        }
-
-        mimeHeaderBlock_ = buf_.consume(mimeHeaderBytes);
-        debugs(74, 5, "mime header (0-" << mimeHeaderBytes << ") {" << mimeHeaderBlock_ << "}");
-
     } else
         debugs(33, 3, "Missing HTTP/1.x identifier");
 
index 734971c13de42175df7fdf4d37038107aa9c0d5d..42ddb52201c17e2f8fe1586868d88bb743a05c23 100644 (file)
@@ -108,14 +108,15 @@ protected:
     bool skipLineTerminator(::Parser::Tokenizer &tok) const;
 
     /**
-     * Parse scan to find the mime headers block for current message.
+     * Scan to find the mime headers block for current message.
      *
-     * \retval true if mime block (or a blocks non-existence) has been
-     *              identified accurately within limit characters.
-     *              mimeHeaderBlock_ has been updated and buf_ consumed.
-     * \retval false an error occured, or no MIME terminator found within limit.
+     * \retval true   If mime block (or a blocks non-existence) has been
+     *                identified accurately within limit characters.
+     *                mimeHeaderBlock_ has been updated and buf_ consumed.
+     *
+     * \retval false  An error occured, or no mime terminator found within limit.
      */
-    bool findMimeBlock(const char *which, const size_t limit);
+    bool grabMimeBlock(const char *which, const size_t limit);
 
     /// RFC 7230 section 2.6 - 7 magic octets
     static const SBuf Http1magic;
index 3bd18452e48ba99872ac8f77e2ae418e6b28f8d4..c47ef3741f62b5f4501e9d99698ed87131951d0f 100644 (file)
@@ -331,7 +331,7 @@ Http::One::RequestParser::parse(const SBuf &aBuf)
     // stage 3: locate the mime header block
     if (parsingStage_ == HTTP_PARSE_MIME) {
         // HTTP/1.x request-line is valid and parsing completed.
-        if (!findMimeBlock("Request", Config.maxRequestHeaderSize)) {
+        if (!grabMimeBlock("Request", Config.maxRequestHeaderSize)) {
             if (parseStatusCode == Http::scHeaderTooLarge)
                 parseStatusCode = Http::scRequestHeaderFieldsTooLarge;
             return false;
index 53b80f6f998c93b462aedb3c8c19c8e2a4826e66..d3bfc9bc918b554909075f1fe8ed921a95ab947b 100644 (file)
@@ -208,7 +208,7 @@ Http::One::ResponseParser::parse(const SBuf &aBuf)
     if (parsingStage_ == HTTP_PARSE_FIRST) {
         PROF_start(HttpParserParseReplyLine);
 
-        int retcode = parseResponseFirstLine();
+        const int retcode = parseResponseFirstLine();
 
         // first-line (or a look-alike) found successfully.
         if (retcode > 0)
@@ -230,7 +230,7 @@ Http::One::ResponseParser::parse(const SBuf &aBuf)
 
     // stage 3: locate the mime header block
     if (parsingStage_ == HTTP_PARSE_MIME) {
-        if (!findMimeBlock("Response", Config.maxReplyHeaderSize))
+        if (!grabMimeBlock("Response", Config.maxReplyHeaderSize))
             return false;
     }