From: Amos Jeffries Date: Sun, 5 Jan 2014 21:15:23 +0000 (-0800) Subject: Handle invalid/unsupported HTTP/X.X versions at parsing version label X-Git-Tag: merge-candidate-3-v1~506^2~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c09f150709302d14c9235051a9bbf3c8310ee37e;p=thirdparty%2Fsquid.git Handle invalid/unsupported HTTP/X.X versions at parsing version label There is no need to duplicate the error response client-streams setup. invalid-version and unsupported-version differ only in error page displayed and the invalid-version page was supposed to be the same as unsupported-version anyway. --- diff --git a/src/client_side.cc b/src/client_side.cc index 8e14db0f92..5b6ab45b6b 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -2566,12 +2566,17 @@ clientProcessRequest(ConnStateData *conn, Http1::RequestParser &hp, ClientSocket assert (repContext); switch (hp.request_parse_status) { case Http::scHeaderTooLarge: - repContext->setReplyToError(ERR_TOO_BIG, Http::scBadRequest, method, http->uri, conn->clientConnection->remote, NULL, conn->in.buf, NULL); + repContext->setReplyToError(ERR_TOO_BIG, Http::scBadRequest, method, http->uri, + conn->clientConnection->remote, NULL, conn->in.buf, NULL); break; case Http::scMethodNotAllowed: repContext->setReplyToError(ERR_UNSUP_REQ, Http::scMethodNotAllowed, method, http->uri, conn->clientConnection->remote, NULL, conn->in.buf, NULL); break; + case Http::scHttpVersionNotSupported: + repContext->setReplyToError(ERR_UNSUP_HTTPVERSION, Http::scHttpVersionNotSupported, method, http->uri, + conn->clientConnection->remote, NULL, conn->in.buf, NULL); + break; default: repContext->setReplyToError(ERR_INVALID_REQ, hp.request_parse_status, method, http->uri, conn->clientConnection->remote, NULL, conn->in.buf, NULL); @@ -2595,25 +2600,6 @@ clientProcessRequest(ConnStateData *conn, Http1::RequestParser &hp, ClientSocket goto finish; } - /* RFC 2616 section 10.5.6 : handle unsupported HTTP major versions cleanly. */ - /* We currently only support 0.9, 1.0, 1.1 properly */ - if ( (http_ver.major == 0 && http_ver.minor != 9) || - (http_ver.major > 1) ) { - - clientStreamNode *node = context->getClientReplyContext(); - debugs(33, 5, "Unsupported HTTP version discovered. :\n" << hp.messageProtocol()); - conn->quitAfterError(request.getRaw()); - // setLogUri should called before repContext->setReplyToError - setLogUri(http, http->uri, true); - clientReplyContext *repContext = dynamic_cast(node->data.getRaw()); - assert (repContext); - repContext->setReplyToError(ERR_UNSUP_HTTPVERSION, Http::scHttpVersionNotSupported, method, http->uri, - conn->clientConnection->remote, NULL, hp.rawHeaderBuf(), NULL); - assert(context->http->out.offset == 0); - context->pullData(); - goto finish; - } - /* compile headers */ if (http_ver.major >= 1 && !request->parseHeader(hp.rawHeaderBuf(), hp.headerBlockSize())) { clientStreamNode *node = context->getClientReplyContext(); diff --git a/src/http/Http1Parser.cc b/src/http/Http1Parser.cc index ff5c84276d..e3dfc2b123 100644 --- a/src/http/Http1Parser.cc +++ b/src/http/Http1Parser.cc @@ -366,6 +366,13 @@ Http1::RequestParser::parseRequestFirstLine() } msgProtocol_.minor = min; + /* RFC 2616 section 10.5.6 : handle unsupported HTTP major versions cleanly. */ + /* We currently only support 0.9, 1.0, 1.1 properly in this parser */ + if ((maj == 0 && min != 9) || (maj > 1)) { + request_parse_status = Http::scHttpVersionNotSupported; + return -1; + } + /* * Rightio - we have all the schtuff. Return true; we've got enough. */