]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: cli: Reject payload with no command
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Sep 2026 08:09:40 +0000 (10:09 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Sep 2026 09:41:18 +0000 (11:41 +0200)
No error is reported during command line parsing when a payload pattern is
found with no command. It is not really a big deal because when the command
is processed, because there is no command, nothing is executed. It is
harmless.

But, accordingly to the doc, the payload is the last argument of a
command. So a command is required. Thus, an error is now reported when a
payload is received with no command.

This patch could be backported to 3.4. Older versions could benefit of this
patch. If we decide to backport it farther, the patch will have to be
adapted.

src/cli.c

index 26f83422419a2c35d73d96b6aef22c4b2bc49211..ecca43d1a53d0015960ced8668adefee1638c83d 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1112,6 +1112,11 @@ int cli_parse_cmdline(struct appctx *appctx)
                                continue;
                        }
 
+                       while (*str && (*str == ' ' || *str == '\t')) {
+                               str++;
+                               len--;
+                       }
+
                        if (!len)
                                goto process_cmdline;
 
@@ -1146,6 +1151,11 @@ int cli_parse_cmdline(struct appctx *appctx)
                        if (strncmp(last_arg, PAYLOAD_PATTERN, strlen(PAYLOAD_PATTERN)) == 0) {
                                ssize_t pat_len = strlen(last_arg) - strlen(PAYLOAD_PATTERN);
 
+                               if (str == last_arg) {
+                                       cli_err(appctx, "The payload cannot be passed without command.\n");
+                                       goto error;
+                               }
+
                                /* A customized pattern can't be more than 64 characters
                                 * if it's more, don't make it a payload
                                 */