From f2846f7377130573523e697a5ca0a557f73e4ef3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 2 Sep 2021 19:46:08 +0200 Subject: [PATCH] BUG/MINOR: vars: properly set the argument parsing context in the expression When the expression called in "set-var" uses argments that require late resolution, the context must be set. At the moment, any unknown argument is misleadingly reported as "ACL": frontend f bind :8080 mode http http-request set-var(proc.a) be_conn(foo) parsing [b1.cfg:4]: unable to find backend 'foo' referenced in arg 1 \ of ACL keyword 'be_conn' in proxy 'f'. Once the context is properly set, it now says the truth: parsing [b1.cfg:8]: unable to find backend 'foo' referenced in arg 1 \ of sample fetch keyword 'be_conn' in http-request expression in proxy 'f'. This may be backported but is not really important. If so, the preceeding patches "BUG/MINOR: vars: improve accuracy of the rules used to check expression validity" and "MINOR: sample: add missing ARGC_ entries" must be backported as well. (cherry picked from commit 54b96d99556a27e15ee77b8b498d011cda2771e9) Signed-off-by: Christopher Faulet (cherry picked from commit a59858fe2410c07670b7a2d00f4c0e1aa9a67bf1) [cf: backported to ease other backports] Signed-off-by: Christopher Faulet --- src/vars.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/vars.c b/src/vars.c index 319088c..79d6b15 100644 --- a/src/vars.c +++ b/src/vars.c @@ -788,29 +788,30 @@ static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy kw_name = args[*arg-1]; - rule->arg.vars.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, - px->conf.args.line, err, (px->id == NULL) ? NULL : &px->conf.args, NULL); - if (!rule->arg.vars.expr) - return ACT_RET_PRS_ERR; - switch (rule->from) { case ACT_F_TCP_REQ_SES: flags = SMP_VAL_FE_SES_ACC; + px->conf.args.ctx = ARGC_TSE; break; case ACT_F_TCP_REQ_CNT: flags = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_REQ_CNT : SMP_VAL_BE_REQ_CNT; + px->conf.args.ctx = ARGC_TRQ; break; case ACT_F_TCP_RES_CNT: flags = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_RES_CNT : SMP_VAL_BE_RES_CNT; + px->conf.args.ctx = ARGC_TRS; break; case ACT_F_HTTP_REQ: flags = (px->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR; + px->conf.args.ctx = ARGC_HRQ; break; case ACT_F_HTTP_RES: flags = (px->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR; + px->conf.args.ctx = ARGC_HRS; break; case ACT_F_TCP_CHK: flags = SMP_VAL_BE_CHK_RUL; + px->conf.args.ctx = ARGC_TCK; break; default: memprintf(err, @@ -818,6 +819,12 @@ static enum act_parse_ret parse_store(const char **args, int *arg, struct proxy rule->from); return ACT_RET_PRS_ERR; } + + rule->arg.vars.expr = sample_parse_expr((char **)args, arg, px->conf.args.file, + px->conf.args.line, err, (px->id == NULL) ? NULL : &px->conf.args, NULL); + if (!rule->arg.vars.expr) + return ACT_RET_PRS_ERR; + if (!(rule->arg.vars.expr->fetch->val & flags)) { memprintf(err, "fetch method '%s' extracts information from '%s', none of which is available here", -- 1.7.10.4