details:   http://freenginx.org/hg/nginx/rev/b401e3f56bda
branches:  
changeset: 9450:b401e3f56bda
user:      Maxim Dounin <[email protected]>
date:      Mon Dec 15 01:16:02 2025 +0300
description:
GeoIP: rearranged checks to avoid dead code.

The "ngx_http_geoip_mmdb_file() == NGX_OK" checks are not executed when
both the legacy GeoIP library and libmaxminddb available, and Coverity
complains that the code is dead.  Fix is to rearrange to code so the
checks are not compiled at all if both libraries are available.

Prodded by Coverity.

diffstat:

 src/http/modules/ngx_http_geoip_module.c |  30 ++++++++++++++++++------------
 src/stream/ngx_stream_geoip_module.c     |  30 ++++++++++++++++++------------
 2 files changed, 36 insertions(+), 24 deletions(-)

diffs (132 lines):

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
@@ -1112,14 +1112,16 @@ ngx_http_geoip_country(ngx_conf_t *cf, n
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_http_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1213,14 +1215,16 @@ ngx_http_geoip_org(ngx_conf_t *cf, ngx_c
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_http_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1320,14 +1324,16 @@ ngx_http_geoip_city(ngx_conf_t *cf, ngx_
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_http_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
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
@@ -1049,14 +1049,16 @@ ngx_stream_geoip_country(ngx_conf_t *cf,
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_stream_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1150,14 +1152,16 @@ ngx_stream_geoip_org(ngx_conf_t *cf, ngx
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_stream_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1257,14 +1261,16 @@ ngx_stream_geoip_city(ngx_conf_t *cf, ng
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_stream_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);

Reply via email to