]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: vars: pre-create parsed SCOPE_PROC variables as permanent ones
authorWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 09:07:32 +0000 (11:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 8 Sep 2021 13:06:11 +0000 (15:06 +0200)
All variables whose names are parsed by the config parser, the
command-line parser or the SPOE's register-var-names parser are
now preset as permanent. This will guarantee that these variables
will exist through out all the process' life, and that it will be
possible to implement the "ifexist" feature by looking them up.

This was marked medium because pre-setting a variable with an empty
value may always have side effects, even though none was spotted at
this stage.

src/vars.c

index 6fc58dd33b2cfcf14ce8d086b10d4cd6909de0fd..30bcf3df9605ed23d2df32d68d088e1ab5c3d31b 100644 (file)
@@ -529,6 +529,7 @@ int vars_check_arg(struct arg *arg, char **err)
 {
        char *name;
        enum vars_scope scope;
+       struct sample empty_smp = { };
 
        /* Check arg type. */
        if (arg->type != ARGT_STR) {
@@ -543,6 +544,9 @@ int vars_check_arg(struct arg *arg, char **err)
        if (!name)
                return 0;
 
+       if (scope == SCOPE_PROC && !var_set(name, scope, &empty_smp, VF_CREATEONLY|VF_PERMANENT))
+               return 0;
+
        /* properly destroy the chunk */
        chunk_destroy(&arg->data.str);
 
@@ -823,6 +827,7 @@ static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy
        int var_len;
        const char *kw_name;
        int flags, set_var = 0; /* 0=unset-var, 1=set-var, 2=set-var-fmt */
+       struct sample empty_smp = { };
 
        if (strncmp(var_name, "set-var-fmt", 11) == 0) {
                var_name += 11;
@@ -856,6 +861,10 @@ static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy
        if (!rule->arg.vars.name)
                return ACT_RET_PRS_ERR;
 
+       if (rule->arg.vars.scope == SCOPE_PROC &&
+           !var_set(rule->arg.vars.name, rule->arg.vars.scope, &empty_smp, VF_CREATEONLY|VF_PERMANENT))
+               return 0;
+
        /* There is no fetch method when variable is unset. Just set the right
         * action and return. */
        if (!set_var) {