[PATCH 3 of 3] Geo: fixed Valgrind complaints about uninitialized values
Maxim Dounin
mdounin at mdounin.ru
Wed Nov 19 14:10:40 UTC 2025
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1763527854 -10800
# Wed Nov 19 07:50:54 2025 +0300
# Node ID 4b46d6ba035fc38f85dae96dfdd0f9e518e3d46e
# Parent 38d3d6ce245e081a4551dbad95e04d3a78ffca39
Geo: fixed Valgrind complaints about uninitialized values.
In ngx_http_geo_value(), variable values were initialized to the extent
used by the lookup code. But the same structures are also fully copied
into the binary range base by ngx_http_geo_copy_values(), including
unused members and padding, and Valgrind complains about uninitialized
memory being used:
==42== Use of uninitialised value of size 8
==42== at 0x40F0C20: ngx_crc32_long (ngx_crc32.h:46)
==42== by 0x40F0C20: ngx_http_geo_create_binary_base (ngx_http_geo_module.c:1648)
==42== by 0x40F0C20: ngx_http_geo_block (ngx_http_geo_module.c:516)
==42== by 0x404BA94: ngx_conf_handler (ngx_conf_file.c:463)
==42== by 0x404BA94: ngx_conf_parse (ngx_conf_file.c:319)
==42== by 0x408C462: ngx_http_block (ngx_http.c:239)
==42== by 0x404BA94: ngx_conf_handler (ngx_conf_file.c:463)
==42== by 0x404BA94: ngx_conf_parse (ngx_conf_file.c:319)
==42== by 0x4048880: ngx_init_cycle (ngx_cycle.c:286)
==42== by 0x40348EB: main (nginx.c:293)'
Fix is to fully initialize ngx_http_variable_value_t structures during
allocation by using ngx_pcalloc().
Prodded by Valgrind.
diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -1259,7 +1259,7 @@ ngx_http_geo_value(ngx_conf_t *cf, ngx_h
return gvvn->value;
}
- val = ngx_palloc(ctx->pool, sizeof(ngx_http_variable_value_t));
+ val = ngx_pcalloc(ctx->pool, sizeof(ngx_http_variable_value_t));
if (val == NULL) {
return NULL;
}
diff --git a/src/stream/ngx_stream_geo_module.c b/src/stream/ngx_stream_geo_module.c
--- a/src/stream/ngx_stream_geo_module.c
+++ b/src/stream/ngx_stream_geo_module.c
@@ -1209,7 +1209,7 @@ ngx_stream_geo_value(ngx_conf_t *cf, ngx
return gvvn->value;
}
- val = ngx_palloc(ctx->pool, sizeof(ngx_stream_variable_value_t));
+ val = ngx_pcalloc(ctx->pool, sizeof(ngx_stream_variable_value_t));
if (val == NULL) {
return NULL;
}
More information about the nginx-devel
mailing list