From cd71cac812b334b59cbfc738772d760ae8288ba3 Mon Sep 17 00:00:00 2001 From: Azmeer Date: Wed, 25 Mar 2026 09:21:03 +0500 Subject: [PATCH] http: warn about duplicate index entries --- src/http/modules/ngx_http_index_module.c | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c index 18e7049c5..bf3401ae3 100644 --- a/src/http/modules/ngx_http_index_module.c +++ b/src/http/modules/ngx_http_index_module.c @@ -458,15 +458,13 @@ ngx_http_index_init(ngx_conf_t *cf) } -/* TODO: warn about duplicate indices */ - static char * ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_index_loc_conf_t *ilcf = conf; ngx_str_t *value; - ngx_uint_t i, n; + ngx_uint_t i, j, n; ngx_http_index_t *index; ngx_http_script_compile_t sc; @@ -494,6 +492,36 @@ ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } + if (ilcf->indices->nelts) { + ngx_http_index_t *old; + size_t len; + + old = ilcf->indices->elts; + + for (j = 0; j < ilcf->indices->nelts; j++) { + + if (old[j].lengths || old[j].values) { + continue; + } + + len = old[j].name.len; + + if (old[j].name.data[0] != '/') { + len--; + } + + if (len == value[i].len + && ngx_strncmp(old[j].name.data, value[i].data, len) == 0) + { + ngx_conf_log_error(NGX_LOG_WARN, cf, 0, + "duplicate index \"%V\" in \"index\" " + "directive", + &value[i]); + break; + } + } + } + index = ngx_array_push(ilcf->indices); if (index == NULL) { return NGX_CONF_ERROR;