]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 2745: Invalid response error on small reads
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 22 Aug 2009 10:43:54 +0000 (22:43 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 22 Aug 2009 10:43:54 +0000 (22:43 +1200)
Also adds extra unit-tests for these cases.

src/HttpReply.cc
src/tests/testHttpReply.cc

index 16538b95164d709c8ffed8b946c3dcc9c98e0392..ca7b537c22834863e4c85db2210ab280c74cc3f8 100644 (file)
@@ -481,7 +481,7 @@ HttpReply::sanityCheckStartLine(MemBuf *buf, const size_t hdr_len, http_status *
     // skip arbitrary number of spaces...
     while (pos <= buf->contentSize() && (char)*(buf->content()+pos) == ' ') ++pos;
 
-    if (!xisdigit(*(buf->content()+pos))) {
+    if (pos < buf->contentSize() && !xisdigit(*(buf->content()+pos))) {
         debugs(58, 3, "HttpReply::sanityCheckStartLine: missing or invalid status number in '" << buf->content() << "'");
         *error = HTTP_INVALID_HEADER;
         return false;
index 81fa94e95401b97e8b4f1cd889c1c9cee9a8e58b..ea064276f4228a20b9a9f45e92663cc80f81676f 100644 (file)
@@ -129,7 +129,48 @@ testHttpReply::testSanityCheckFirstLine()
     input.reset();
     error = HTTP_STATUS_NONE;
 
-#if FUTURE
+    // incomplete (short) status lines... not sane (yet), but no error either.
+    input.append("H", 1);
+    hdr_len = headersEnd(input.content(),input.contentSize());
+    CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
+    CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
+    input.reset();
+    error = HTTP_STATUS_NONE;
+
+    input.append("HTTP/", 5);
+    hdr_len = headersEnd(input.content(),input.contentSize());
+    CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
+    CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
+    input.reset();
+    error = HTTP_STATUS_NONE;
+
+    input.append("HTTP/1", 6);
+    hdr_len = headersEnd(input.content(),input.contentSize());
+    CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
+    CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
+    input.reset();
+    error = HTTP_STATUS_NONE;
+
+    input.append("HTTP/1.1", 8);
+    hdr_len = headersEnd(input.content(),input.contentSize());
+    CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
+    CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
+    input.reset();
+    error = HTTP_STATUS_NONE;
+
+    input.append("HTTP/1.1 ", 9); /* real case seen */
+    hdr_len = headersEnd(input.content(),input.contentSize());
+    CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) );
+    CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
+    input.reset();
+    error = HTTP_STATUS_NONE;
+
+    input.append("HTTP/1.1    20", 14);
+    hdr_len = headersEnd(input.content(),input.contentSize());
+    CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) );
+    CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
+    input.reset();
+    error = HTTP_STATUS_NONE;
 
     // status line with no status
     input.append("HTTP/1.1 \n\n", 11);
@@ -178,6 +219,5 @@ testHttpReply::testSanityCheckFirstLine()
     CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
     input.reset();
     error = HTTP_STATUS_NONE;
-#endif
 
 }