Clearing a permanent variable with unset-var frees its stored name even
though the struct var entry stays alive, hiding subsequent values from
prefix-filtered dump_all_vars() calls and falling back to printing its
internal hash digest.

In src/vars.c, var_clear() calls ha_free(&var->name) unconditionally at
the top of the function before checking (!(var->flags & VF_PERMANENT) ||
force). When set-var later assigns a new value to that VF_PERMANENT
variable, it reuses the existing struct var with var->name == NULL, so
dump_all_vars() with a prefix skips it and unfiltered dump_all_vars()
prints "var_<name_hash>".

Move ha_free(&var->name) inside the deletion block so permanent
variables retain their name until force != 0.

This was introduced by commit 95e8483b3 ("MINOR: vars: store variable
names for runtime access") in 3.4-dev3, and must be backported to 3.5
and 3.4.

Signed-off-by: Dominik Maier <[email protected]>
---
Found with an AI-assisted code review tool (ARTIST) and verified on
HAProxy 3.5.0 (cf7df90c5e5f) and 3.6-dev0 (5f19999d51c9).
Please keep me CC'd on replies as I am not subscribed to the list.

 src/vars.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/vars.c b/src/vars.c
index 29ca311ab..5a7845d7b 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -228,8 +228,6 @@ unsigned int var_clear(struct vars *vars, struct var *var, int force)
 {
        unsigned int size = 0;

-       ha_free(&var->name);
-
        if (var->data.type == SMP_T_STR || var->data.type == SMP_T_BIN) {
                ha_free(&var->data.u.str.area);
                size += var->data.u.str.data;
@@ -242,6 +240,7 @@ unsigned int var_clear(struct vars *vars, struct var *var, int force)
        var->data.type = SMP_T_ANY;

        if (!(var->flags & VF_PERMANENT) || force) {
+               ha_free(&var->name);
                cebu64_item_delete(&vars->name_root[var->name_hash % 
VAR_NAME_ROOTS],
                                   name_node, name_hash, var);
                pool_free(var_pool, var);


Reply via email to