]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: stick-tables/cli: "set table" without key must not clear the table
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 17 Nov 2026 12:48:25 +0000 (13:48 +0100)
committerOlivier Houchard <cognet@ci0.org>
Tue, 17 Nov 2026 12:41:28 +0000 (13:41 +0100)
cli_parse_table_req() accepts "set table <table>" without any "key" nor
"ptr" argument and returns 0, so that the table I/O handler runs with the
"set" action, which, like "clear", kills all unreferenced entries of the
table. So an operator mistyping "set table t" silently wipes the whole
table instead of getting an error (the doc's synopsis lists key/ptr as
required):

  > set table t key 10.0.0.1 data.gpc0 1   (x4)
  > show table t     => used:4
  > set table t      => (no output)
  > show table t     => used:0

Let's return the usage message when "set" is used without key nor ptr.

This was introduced in 1.7 by commit f13ebdf28 ("REORG: cli: move table
dump/clear/set to stick_table.c") which made "set" use the table I/O
handler. Before that, it was a no-op. This should be backported to all
stable versions.

src/stick_table.c

index dd8ee3504a4ad01bb35154371b1f0bc052477fb1..43a3b835d8c60041fab2687e33832b0a25d54a4e 100644 (file)
@@ -5797,8 +5797,8 @@ static int cli_parse_table_req(char **args, char *payload, struct appctx *appctx
                return table_process_entry_per_ptr(appctx, args);
        else if (strncmp(args[3], "data.", 5) == 0)
                return table_prepare_data_request(appctx, args);
-       else if (*args[3])
-               goto err_args;
+       else if (*args[3] || ctx->action == STK_CLI_ACT_SET)
+               goto err_args; /* "set" requires a key or a ptr */
 
        return 0;