From: Eduard Bagdasaryan Date: Sun, 23 Jun 2019 14:14:47 +0000 (+0000) Subject: Fix handling of tiny invalid responses (#422) X-Git-Tag: SQUID_5_0_1~78 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=26e3e64019d5d8adc3f16ed2a0547e828b4007f5;p=thirdparty%2Fsquid.git Fix handling of tiny invalid responses (#422) Squid converted any invalid response shorter than 4 bytes into an invalid "HTTP/1.1 0 Init" response (with those received characters and a CRLFCRLF suffix as a body). In some cases (e.g., with ICAP RESPMOD), the resulting body was not sent to the client at all. Now Squid handles such responses the same way it handles any non-HTTP/1 (and non-ICY) response, converting it into a valid HTTP/200 response with an X-Transformed-From:HTTP/0.9 header and received bytes as a message body. --- diff --git a/src/HttpReply.cc b/src/HttpReply.cc index e5e1c8f1bf..c63fccdf30 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -491,6 +491,7 @@ HttpReply::expectingBody(const HttpRequestMethod& req_method, int64_t& theSize) expectBody = false; else if (sline.status() == Http::scNotModified) expectBody = false; + // TODO: Consider assuming that gray-area 0xx responses have bodies, like 9xx responses. else if (sline.status() < Http::scOkay) expectBody = false; else diff --git a/src/http/one/ResponseParser.cc b/src/http/one/ResponseParser.cc index 4d09a03cc1..24f0248d5e 100644 --- a/src/http/one/ResponseParser.cc +++ b/src/http/one/ResponseParser.cc @@ -158,8 +158,13 @@ Http::One::ResponseParser::parseResponseFirstLine() debugs(74, DBG_DATA, "parse remaining buf={length=" << tok.remaining().length() << ", data='" << tok.remaining() << "'}"); buf_ = tok.remaining(); // resume checkpoint return parseResponseStatusAndReason(tok, WspDelim); - - } else if (buf_.length() > Http1magic.length() && buf_.length() > IcyMagic.length()) { + } else if (buf_.length() < Http1magic.length() && Http1magic.startsWith(buf_)) { + debugs(74, 7, Raw("valid HTTP/1 prefix", buf_.rawContent(), buf_.length())); + return 0; + } else if (buf_.length() < IcyMagic.length() && IcyMagic.startsWith(buf_)) { + debugs(74, 7, Raw("valid ICY prefix", buf_.rawContent(), buf_.length())); + return 0; + } else { debugs(74, 2, "unknown/missing prefix magic. Interpreting as HTTP/0.9"); // found something that looks like an HTTP/0.9 response // Gateway/Transform it into HTTP/1.1 @@ -179,7 +184,9 @@ Http::One::ResponseParser::parseResponseFirstLine() return 1; // no more parsing } - return 0; // need more to parse anything. + // unreachable + assert(false); + return -1; } bool