# HG changeset patch # User Igor Sysoev # Date 1218644748 0 # Node ID a69886fc2864d5e17741692134aa4456d666a465 # Parent 20a7fc523aecec5a46c04f90a22610baa1501c8a *) fix segfaults in types hash *) fix inheritance: default hash instead of inherited one diff --git a/src/http/modules/ngx_http_charset_filter_module.c b/src/http/modules/ngx_http_charset_filter_module.c --- a/src/http/modules/ngx_http_charset_filter_module.c +++ b/src/http/modules/ngx_http_charset_filter_module.c @@ -1484,6 +1484,14 @@ ngx_http_charset_merge_loc_conf(ngx_conf ngx_http_charset_recode_t *recode; ngx_http_charset_main_conf_t *mcf; + if (ngx_http_merge_types(cf, conf->types_keys, &conf->types, + prev->types_keys, &prev->types, + ngx_http_charset_default_types) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + ngx_conf_merge_value(conf->override_charset, prev->override_charset, 0); ngx_conf_merge_value(conf->charset, prev->charset, NGX_HTTP_NO_CHARSET); @@ -1523,14 +1531,6 @@ ngx_http_charset_merge_loc_conf(ngx_conf recode->src = conf->source_charset; recode->dst = conf->charset; - if (ngx_http_merge_types(cf, conf->types_keys, &conf->types, - prev->types_keys, &prev->types, - ngx_http_charset_default_types) - != NGX_OK) - { - return NGX_CONF_ERROR; - } - return NGX_CONF_OK; } diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -1761,43 +1761,60 @@ ngx_http_types_slot(ngx_conf_t *cf, ngx_ char * ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash, - ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash, + ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash, ngx_str_t *default_types) { ngx_hash_init_t hash; - if (keys == NULL) { + if (keys) { - if (prev_keys) { - *types_hash = *prev_types_hash; - return NGX_CONF_OK; + hash.hash = types_hash; + hash.key = NULL; + hash.max_size = 2048; + hash.bucket_size = 64; + hash.name = "test_types_hash"; + hash.pool = cf->pool; + hash.temp_pool = NULL; + + if (ngx_hash_init(&hash, keys->elts, keys->nelts) != NGX_OK) { + return NGX_CONF_ERROR; } - if (ngx_http_set_default_types(cf, &keys, default_types) - != NGX_CONF_OK) - { + return NGX_CONF_OK; + } + + if (prev_types_hash->buckets == NULL) { + + if (prev_keys == NULL) { + + if (ngx_http_set_default_types(cf, &prev_keys, default_types) + != NGX_OK) + { + return NGX_CONF_ERROR; + } + } + + hash.hash = prev_types_hash; + hash.key = NULL; + hash.max_size = 2048; + hash.bucket_size = 64; + hash.name = "test_types_hash"; + hash.pool = cf->pool; + hash.temp_pool = NULL; + + if (ngx_hash_init(&hash, prev_keys->elts, prev_keys->nelts) != NGX_OK) { return NGX_CONF_ERROR; } } - hash.hash = types_hash; - hash.key = NULL; - hash.max_size = 2048; - hash.bucket_size = 64; - hash.name = "test_types_hash"; - hash.pool = cf->pool; - hash.temp_pool = NULL; - - if (ngx_hash_init(&hash, keys->elts, keys->nelts) != NGX_OK) { - return NGX_CONF_ERROR; - } + *types_hash = *prev_types_hash; return NGX_CONF_OK; } -char * +ngx_int_t ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types, ngx_str_t *default_type) { @@ -1805,14 +1822,14 @@ ngx_http_set_default_types(ngx_conf_t *c *types = ngx_array_create(cf->temp_pool, 1, sizeof(ngx_hash_key_t)); if (*types == NULL) { - return NGX_CONF_ERROR; + return NGX_ERROR; } while (default_type->len) { type = ngx_array_push(*types); if (type == NULL) { - return NGX_CONF_ERROR; + return NGX_ERROR; } type->key = *default_type; @@ -1823,5 +1840,5 @@ ngx_http_set_default_types(ngx_conf_t *c default_type++; } - return NGX_CONF_OK; + return NGX_OK; } diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -111,7 +111,7 @@ char *ngx_http_types_slot(ngx_conf_t *cf char *ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t *keys, ngx_hash_t *types_hash, ngx_array_t *prev_keys, ngx_hash_t *prev_types_hash, ngx_str_t *default_types); -char *ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types, +ngx_int_t ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types, ngx_str_t *default_type);