]> git.kaiwu.me - nginx.git/commitdiff
Added protection against r->main->count overflow by subrequests.
authorValentin Bartenev <vbart@nginx.com>
Mon, 31 Aug 2015 20:25:16 +0000 (23:25 +0300)
committerValentin Bartenev <vbart@nginx.com>
Mon, 31 Aug 2015 20:25:16 +0000 (23:25 +0300)
This overflow has become possible after the change in 06e850859a26,
since concurrent subrequests are not limited now and each of them is
counted in r->main->count.

src/http/ngx_http_core_module.c
src/http/ngx_http_request.h

index 24627308e089d53ec19a984eec9c2631196bfeb5..0a5b6b47b74bfec20190ab9af949cd6cb553c629 100644 (file)
@@ -2433,6 +2433,16 @@ ngx_http_subrequest(ngx_http_request_t *r,
         return NGX_ERROR;
     }
 
+    /*
+     * 1000 is reserved for other purposes.
+     */
+    if (r->main->count >= 65535 - 1000) {
+        ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
+                      "request reference counter overflow "
+                      "while processing \"%V\"", uri);
+        return NGX_ERROR;
+    }
+
     sr = ngx_pcalloc(r->pool, sizeof(ngx_http_request_t));
     if (sr == NULL) {
         return NGX_ERROR;
index 3954de3f1608a59034b74e584f46f4879bba2803..7e56c399d2a989691960f48169bac7dfa87397ee 100644 (file)
@@ -439,8 +439,8 @@ struct ngx_http_request_s {
 
     ngx_http_cleanup_t               *cleanup;
 
+    unsigned                          count:16;
     unsigned                          subrequests:8;
-    unsigned                          count:8;
     unsigned                          blocked:8;
 
     unsigned                          aio:1;