]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: vars: support storing empty sample data with a variable
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 11:58:19 +0000 (13:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 11:59:43 +0000 (13:59 +0200)
Storing an unset sample (SMP_T_ANY == 0) will be used to only reserve
the variable's space but associate no value. We need to slightly adjust
var_to_smp() for this so that it considers a value-less variable as non
existent and falls back to the default value.

src/vars.c

index 80a6a4520c6164e78afdcd286c2ca7f1c632c484..52f19c560c4018e96d63f8b193f166060d8643c5 100644 (file)
@@ -591,9 +591,9 @@ int vars_unset_by_name_ifexist(const char *name, size_t len, struct sample *smp)
 }
 
 
-/* This retrieves variable <name> from variables <vars>, and if found,
- * duplicates the result into sample <smp>. smp_dup() is used in order to
- * release the variables lock ASAP (so a pre-allocated chunk is obtained
+/* This retrieves variable <name> from variables <vars>, and if found and not
+ * empty, duplicates the result into sample <smp>. smp_dup() is used in order
+ * to release the variables lock ASAP (so a pre-allocated chunk is obtained
  * via get_trash_shunk()). The variables' lock is used for reads.
  *
  * The function returns 0 if the variable was not found and no default
@@ -607,7 +607,7 @@ static int var_to_smp(struct vars *vars, const char *name, struct sample *smp, c
        /* Get the variable entry. */
        HA_RWLOCK_RDLOCK(VARS_LOCK, &vars->rwlock);
        var = var_get(vars, name);
-       if (!var) {
+       if (!var || !var->data.type) {
                if (!def) {
                        HA_RWLOCK_RDUNLOCK(VARS_LOCK, &vars->rwlock);
                        return 0;