]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cli: Issue an error when too many args are passed for a command
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 23 Apr 2025 13:29:00 +0000 (15:29 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Apr 2025 12:58:24 +0000 (14:58 +0200)
When a command is parsed to split it in an array of arguments, by default,
at most 64 arguments are supported. But no warning was emitted when there
were too many arguments. Instead, the arguments above the limit were
silently ignored. It could be an issue for some commands, like "add server",
because there was no way to know some arguments were ignored.

Now an error is issued when too many arguments are passed and the command is
not executed.

This patch should be backported to all stable versions.

src/cli.c

index f06f3c907e90134247aa078076679b182bbe6293..822de4e46b63a08211e917265f6f5089f915baf9 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -806,6 +806,16 @@ static int cli_parse_request(struct appctx *appctx)
        }
        /* fill unused slots */
        p = b_tail(&appctx->inbuf);
+
+       /* throw an error if too many args are provided */
+       if (*p && i == MAX_CLI_ARGS) {
+               char *err = NULL;
+
+               cli_err(appctx, memprintf(&err, "Too many arguments. Commands must have at most %d arguments.\n", MAX_CLI_ARGS));
+               return 0;
+       }
+
+
        for (; i < MAX_CLI_ARGS + 1; i++)
                args[i] = p;