[PATCH 4 of 5] GeoIP: fixed database file names to be resolved from prefix

Maxim Dounin mdounin at mdounin.ru
Fri Oct 24 01:42:40 UTC 2025


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1761147436 -10800
#      Wed Oct 22 18:37:16 2025 +0300
# Node ID c69974d6becb06d4e90db8a05f18f83886c7a668
# Parent  d8642f2ac14d1e5bb73a231c0898e1a1735beb62
GeoIP: fixed database file names to be resolved from prefix.

Previously, relative database file names set by the geoip_country,
geoip_city, and geoip_org configuration directives were not processed
with ngx_conf_full_name() and therefore resolved from the process current
working directory, leading to changes in behaviour depending on the current
directory during startup.  This also differs from the expected behaviour
of configuration directives, where relative paths are expected to be
resolved either from prefix or from configuration prefix.

Fix is to use ngx_conf_full_name() to resolve relative database file names
from prefix.

diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c
--- a/src/http/modules/ngx_http_geoip_module.c
+++ b/src/http/modules/ngx_http_geoip_module.c
@@ -686,6 +686,10 @@ ngx_http_geoip_country(ngx_conf_t *cf, n
 
     value = cf->args->elts;
 
+    if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
     gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
 
     if (gcf->country == NULL) {
@@ -741,6 +745,10 @@ ngx_http_geoip_org(ngx_conf_t *cf, ngx_c
 
     value = cf->args->elts;
 
+    if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
     gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
 
     if (gcf->org == NULL) {
@@ -802,6 +810,10 @@ ngx_http_geoip_city(ngx_conf_t *cf, ngx_
 
     value = cf->args->elts;
 
+    if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
     gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
 
     if (gcf->city == NULL) {
diff --git a/src/stream/ngx_stream_geoip_module.c b/src/stream/ngx_stream_geoip_module.c
--- a/src/stream/ngx_stream_geoip_module.c
+++ b/src/stream/ngx_stream_geoip_module.c
@@ -635,6 +635,10 @@ ngx_stream_geoip_country(ngx_conf_t *cf,
 
     value = cf->args->elts;
 
+    if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
     gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
 
     if (gcf->country == NULL) {
@@ -690,6 +694,10 @@ ngx_stream_geoip_org(ngx_conf_t *cf, ngx
 
     value = cf->args->elts;
 
+    if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
     gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
 
     if (gcf->org == NULL) {
@@ -751,6 +759,10 @@ ngx_stream_geoip_city(ngx_conf_t *cf, ng
 
     value = cf->args->elts;
 
+    if (ngx_conf_full_name(cf->cycle, &value[1], 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
     gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
 
     if (gcf->city == NULL) {



More information about the nginx-devel mailing list