summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2021-08-24 14:57:28 +0200
committerWilly Tarreau <w@1wt.eu>2021-08-24 15:05:48 +0200
commitece4c4a35265cbc28d25826205ee66dbf9ac6f7d (patch)
tree967a19f95fe5c92584998b444c9ed0579a11b727
parent8b673f0fe3dfb16f509cccd5b84024b6304ddb2c (diff)
downloadhaproxy-ece4c4a35265cbc28d25826205ee66dbf9ac6f7d.tar.gz
BUG/MINOR: stick-table: fix the sc-set-gpt* parser when using expressions
The sc-set-gpt0() parser was extended in 2.1 by commit 0d7712dff ("MINOR: stick-table: allow sc-set-gpt0 to set value from an expression") to support sample expressions in addition to plain integers. However there is a subtlety there, which is that while the arg position must be incremented when parsing an integer, it must not be touched when calling an expression since the expression parser already does it. The effect is that rules making use of sc-set-gpt0() followed by an expression always ignore one word after that expression, and will typically fail to parse if followed by an "if" as the parser will restart after the "if". With no condition it's different because an empty condition doesn't result in trying to parse anything. This patch moves the increment at the right place and adds a few explanations for a code part that was far from being obvious. This should be backported to branches having the commit above (2.1+).
-rw-r--r--src/stick_table.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/stick_table.c b/src/stick_table.c
index e50ef2571..6f07080f6 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -2633,9 +2633,13 @@ static enum act_parse_ret parse_set_gpt(const char **args, int *arg, struct prox
return ACT_RET_PRS_ERR;
}
+ /* value may be either an integer or an expression */
rule->arg.gpt.expr = NULL;
rule->arg.gpt.value = strtol(args[*arg], &error, 10);
- if (*error != '\0') {
+ if (*error == '\0') {
+ /* valid integer, skip it */
+ (*arg)++;
+ } else {
rule->arg.gpt.expr = sample_parse_expr((char **)args, arg, px->conf.args.file,
px->conf.args.line, err, &px->conf.args, NULL);
if (!rule->arg.gpt.expr)
@@ -2658,7 +2662,6 @@ static enum act_parse_ret parse_set_gpt(const char **args, int *arg, struct prox
return ACT_RET_PRS_ERR;
}
}
- (*arg)++;
rule->action = ACT_CUSTOM;