]> git.kaiwu.me - nginx.git/commitdiff
Don't pretend we support HTTP major versions >1 as HTTP/1.1.
authorRuslan Ermilov <ru@nginx.com>
Tue, 25 Apr 2017 20:39:13 +0000 (23:39 +0300)
committerRuslan Ermilov <ru@nginx.com>
Tue, 25 Apr 2017 20:39:13 +0000 (23:39 +0300)
src/http/ngx_http_header_filter_module.c
src/http/ngx_http_parse.c
src/http/ngx_http_request.c
src/http/ngx_http_request.h
src/http/ngx_http_special_response.c

index 5fc7e1f1b436addc7809eb59995f427752608623..9b89405904bd361feafa2d9a15e951eca0f3edfb 100644 (file)
@@ -119,7 +119,7 @@ static ngx_str_t ngx_http_status_lines[] = {
     ngx_string("502 Bad Gateway"),
     ngx_string("503 Service Temporarily Unavailable"),
     ngx_string("504 Gateway Time-out"),
-    ngx_null_string,        /* "505 HTTP Version Not Supported" */
+    ngx_string("505 HTTP Version Not Supported"),
     ngx_null_string,        /* "506 Variant Also Negotiates" */
     ngx_string("507 Insufficient Storage"),
 
index 9f994731611af9bb10cfc52b0a30b39e2ece4dfc..36220fdc148706fec3919358e86dd24e7f170820 100644 (file)
@@ -723,6 +723,11 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
             }
 
             r->http_major = ch - '0';
+
+            if (r->http_major > 1) {
+                return NGX_HTTP_PARSE_INVALID_VERSION;
+            }
+
             state = sw_major_digit;
             break;
 
@@ -737,11 +742,12 @@ ngx_http_parse_request_line(ngx_http_request_t *r, ngx_buf_t *b)
                 return NGX_HTTP_PARSE_INVALID_REQUEST;
             }
 
-            if (r->http_major > 99) {
-                return NGX_HTTP_PARSE_INVALID_REQUEST;
+            r->http_major = r->http_major * 10 + ch - '0';
+
+            if (r->http_major > 1) {
+                return NGX_HTTP_PARSE_INVALID_VERSION;
             }
 
-            r->http_major = r->http_major * 10 + ch - '0';
             break;
 
         /* first digit of minor HTTP version */
index 476f0398440d1bc4b9a022f830b77232610b37f6..7af45c586cea01382816a00e2e808f36f63d4f48 100644 (file)
@@ -72,6 +72,9 @@ static char *ngx_http_client_errors[] = {
     /* NGX_HTTP_PARSE_INVALID_REQUEST */
     "client sent invalid request",
 
+    /* NGX_HTTP_PARSE_INVALID_VERSION */
+    "client sent invalid version",
+
     /* NGX_HTTP_PARSE_INVALID_09_METHOD */
     "client sent invalid method in HTTP/0.9 request"
 };
@@ -1036,7 +1039,14 @@ ngx_http_process_request_line(ngx_event_t *rev)
 
             ngx_log_error(NGX_LOG_INFO, c->log, 0,
                           ngx_http_client_errors[rc - NGX_HTTP_CLIENT_ERROR]);
-            ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+
+            if (rc == NGX_HTTP_PARSE_INVALID_VERSION) {
+                ngx_http_finalize_request(r, NGX_HTTP_VERSION_NOT_SUPPORTED);
+
+            } else {
+                ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+            }
+
             return;
         }
 
index 2c77f9323b9c9c0d5495a9a04c4d16e09c45d24e..98c0de769bb5a07ba5c52ce1d9ebee2e5360db82 100644 (file)
 #define NGX_HTTP_CLIENT_ERROR              10
 #define NGX_HTTP_PARSE_INVALID_METHOD      10
 #define NGX_HTTP_PARSE_INVALID_REQUEST     11
-#define NGX_HTTP_PARSE_INVALID_09_METHOD   12
+#define NGX_HTTP_PARSE_INVALID_VERSION     12
+#define NGX_HTTP_PARSE_INVALID_09_METHOD   13
 
-#define NGX_HTTP_PARSE_INVALID_HEADER      13
+#define NGX_HTTP_PARSE_INVALID_HEADER      14
 
 
 /* unused                                  1 */
 #define NGX_HTTP_BAD_GATEWAY               502
 #define NGX_HTTP_SERVICE_UNAVAILABLE       503
 #define NGX_HTTP_GATEWAY_TIME_OUT          504
+#define NGX_HTTP_VERSION_NOT_SUPPORTED     505
 #define NGX_HTTP_INSUFFICIENT_STORAGE      507
 
 
index c4c13053b5853ca4824d3073d6ae053721c5d6fb..2c1ff17439f81337660e0dfc3ae07231e3fc35e9 100644 (file)
@@ -321,6 +321,14 @@ static char ngx_http_error_504_page[] =
 ;
 
 
+static char ngx_http_error_505_page[] =
+"<html>" CRLF
+"<head><title>505 HTTP Version Not Supported</title></head>" CRLF
+"<body bgcolor=\"white\">" CRLF
+"<center><h1>505 HTTP Version Not Supported</h1></center>" CRLF
+;
+
+
 static char ngx_http_error_507_page[] =
 "<html>" CRLF
 "<head><title>507 Insufficient Storage</title></head>" CRLF
@@ -395,7 +403,7 @@ static ngx_str_t ngx_http_error_pages[] = {
     ngx_string(ngx_http_error_502_page),
     ngx_string(ngx_http_error_503_page),
     ngx_string(ngx_http_error_504_page),
-    ngx_null_string,                     /* 505 */
+    ngx_string(ngx_http_error_505_page),
     ngx_null_string,                     /* 506 */
     ngx_string(ngx_http_error_507_page)