]> git.kaiwu.me - nginx.git/commitdiff
Gzip: fixed style in $gzip_ratio variable handler.
authorRuslan Ermilov <ru@nginx.com>
Wed, 14 Jun 2017 09:49:20 +0000 (12:49 +0300)
committerRuslan Ermilov <ru@nginx.com>
Wed, 14 Jun 2017 09:49:20 +0000 (12:49 +0300)
The current style in variable handlers returning NGX_OK is to either set
v->not_found to 1, or to initialize the entire ngx_http_variable_value_t
structure.

In theory, always setting v->valid = 1 for NGX_OK would be useful, which
would mean that the value was computed and is thus valid, including the
special case of v->not_found = 1.  But currently that's not the case and
causes the (v->valid || v->not_found) check to access an uninitialized
v->valid value, which is safe only because its value doesn't matter when
v->not_found is set.

src/http/modules/ngx_http_gzip_filter_module.c

index 287fd3674aba5b0797fde4aa823166db3c5f2a9b..73b6d89bea420ce3a16e68825b9c97d3394e8c47 100644 (file)
@@ -1084,10 +1084,6 @@ ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
     ngx_uint_t            zint, zfrac;
     ngx_http_gzip_ctx_t  *ctx;
 
-    v->valid = 1;
-    v->no_cacheable = 0;
-    v->not_found = 0;
-
     ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
 
     if (ctx == NULL || ctx->zout == 0) {
@@ -1095,6 +1091,10 @@ ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
         return NGX_OK;
     }
 
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+
     v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN + 3);
     if (v->data == NULL) {
         return NGX_ERROR;