]> git.kaiwu.me - nginx.git/commitdiff
Merge of r4636, r4637, r4638: config sanity checks.
authorMaxim Dounin <mdounin@mdounin.ru>
Fri, 29 Jun 2012 17:28:41 +0000 (17:28 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Fri, 29 Jun 2012 17:28:41 +0000 (17:28 +0000)
*) Added syntax checking of the second parameter of the "split_clients"
   directive.

*) Capped the status code that may be returned with "return" and
   "try_files".

*) Zero padded the returned and logged HTTP status code, and fixed possible
   buffer overrun in $status handling.

src/http/modules/ngx_http_log_module.c
src/http/modules/ngx_http_rewrite_module.c
src/http/modules/ngx_http_split_clients_module.c
src/http/ngx_http_core_module.c
src/http/ngx_http_header_filter_module.c

index 2d412853bd95bec9e11ea4146be96dd746ef2268..b3c9a1126939481b39ee1e7386d22428e9f9019b 100644 (file)
@@ -205,7 +205,7 @@ static ngx_http_log_var_t  ngx_http_log_vars[] = {
     { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec },
     { ngx_string("request_time"), NGX_TIME_T_LEN + 4,
                           ngx_http_log_request_time },
-    { ngx_string("status"), 3, ngx_http_log_status },
+    { ngx_string("status"), NGX_INT_T_LEN, ngx_http_log_status },
     { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent },
     { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN,
                           ngx_http_log_body_bytes_sent },
@@ -593,7 +593,7 @@ ngx_http_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op)
         status = 0;
     }
 
-    return ngx_sprintf(buf, "%ui", status);
+    return ngx_sprintf(buf, "%03ui", status);
 }
 
 
index 74d26e524f480aab10922252a0048e3b09d4d349..4081f87743343c775c9901e522d27553bd76a4cb 100644 (file)
@@ -485,6 +485,12 @@ ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     } else {
 
+        if (ret->status > 999) {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "invalid return code \"%V\"", &value[1]);
+            return NGX_CONF_ERROR;
+        }
+
         if (cf->args->nelts == 2) {
             return NGX_CONF_OK;
         }
index 726269c3c733f9bdfd29140f3ce6fa1a090e092c..33a2fe73ee7350d592cca8477d6c87e6ef99978c 100644 (file)
@@ -138,6 +138,13 @@ ngx_conf_split_clients_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     }
 
     name = value[2];
+
+    if (name.len < 2 || name.data[0] != '$') {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                           "invalid variable name \"%V\"", &name);
+        return NGX_CONF_ERROR;
+    }
+
     name.len--;
     name.data++;
 
index 31832ceb8e69b62c36da5923413efca5df0c141c..5bb01d9ea770a987397390490d71fc20c9a34109 100644 (file)
@@ -4662,7 +4662,7 @@ ngx_http_core_try_files(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
         code = ngx_atoi(tf[i - 1].name.data + 1, tf[i - 1].name.len - 2);
 
-        if (code == NGX_ERROR) {
+        if (code == NGX_ERROR || code > 999) {
             ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                "invalid code \"%*s\"",
                                tf[i - 1].name.len - 1, tf[i - 1].name.data);
index 8a6080f6008b2e51e7535169089824f5c4c4b84a..19f531b5db1d30ef16e3cb75cc7a3705c3b76d05 100644 (file)
@@ -445,7 +445,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
         b->last = ngx_copy(b->last, status_line->data, status_line->len);
 
     } else {
-        b->last = ngx_sprintf(b->last, "%ui", status);
+        b->last = ngx_sprintf(b->last, "%03ui", status);
     }
     *b->last++ = CR; *b->last++ = LF;