[PATCH 2 of 2] fix ETag allocation failure

Maxim Dounin mdounin at mdounin.ru
Fri Sep 5 18:27:32 UTC 2014


Hello!

On Sun, Aug 17, 2014 at 11:00:30PM +0300, Markus Linnala wrote:

> # HG changeset patch
> # User Markus Linnala <Markus.Linnala at cybercom.com>
> # Date 1408305457 -10800
> #      Sun Aug 17 22:57:37 2014 +0300
> # Node ID 6af8cc12f3c933eed752e9ca61622d27a909ca00
> # Parent  d350d288cffef0e6395ae1f412842c3b55bc8d42
> fix ETag allocation failure
> 
> diff -r d350d288cffe -r 6af8cc12f3c9 src/http/ngx_http_core_module.c
> --- a/src/http/ngx_http_core_module.c	Sun Aug 17 22:21:56 2014 +0300
> +++ b/src/http/ngx_http_core_module.c	Sun Aug 17 22:57:37 2014 +0300
> @@ -1832,14 +1832,15 @@
>          return NGX_ERROR;
>      }
>  
> +    etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
> +    if (etag->value.data == NULL) {
> +        etag->hash = 0;
> +        return NGX_ERROR;
> +    }
> +
>      etag->hash = 1;
>      ngx_str_set(&etag->key, "ETag");
>  
> -    etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
> -    if (etag->value.data == NULL) {
> -        return NGX_ERROR;
> -    }
> -

I don't think that moving the allocation make sense as anyway 
etag->hash has to be explicitly set in the error path.  Something 
like this should be better:

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1409941111 -14400
#      Fri Sep 05 22:18:31 2014 +0400
# Node ID a80ee1f90b2b2c6cdee4e9b0ba2e0d48cad0f011
# Parent  f43551f64d028de939332ab9b66c3620b4259e08
Fixed ETag memory allocation error handling.

The etag->hash must be set to 0 to avoid an empty ETag header being
returned with the 500 Internal Error page after the memory allocation
failure.

Reported by Markus Linnala.

diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -1837,6 +1837,7 @@ ngx_http_set_etag(ngx_http_request_t *r)
 
     etag->value.data = ngx_pnalloc(r->pool, NGX_OFF_T_LEN + NGX_TIME_T_LEN + 3);
     if (etag->value.data == NULL) {
+        etag->hash = 0;
         return NGX_ERROR;
     }
 

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list