]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mworker/cli: check ci_insert() return value in pcli_parse_request()
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 4 May 2026 17:00:27 +0000 (19:00 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 4 May 2026 17:03:48 +0000 (19:03 +0200)
All ci_insert() calls in pcli_parse_request() were ignoring the return
value, silently miscounting the bytes to forward if an insertion failed.

Add a check on each call and return -1 on failure. In practice this has
no impact: the channel receive machinery enforces a maxrewrite reserve,
so there is always sufficient room in the buffer for these small
prefixes by the time pcli_parse_request() is called.

Must be backported in every maintained versions, the list of available
commands might change.

src/cli.c

index 62158f2d6fbae01bb4f996d2add21484d82d17c8..cab99aa33726bb09f4cddde93bf9f87f2b1172ea 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -3429,27 +3429,42 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
                /* the mcli-debug-mode is only sent to the applet of the master */
                if ((pcli->flags & ACCESS_MCLI_DEBUG) && *next_pid <= 0) {
                        const char *cmd = "mcli-debug-mode on -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                }
                if (pcli->flags & ACCESS_EXPERIMENTAL) {
                        const char *cmd = "experimental-mode on -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                }
                if (pcli->flags & ACCESS_EXPERT) {
                        const char *cmd = "expert-mode on -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                }
                if (pcli->flags & ACCESS_MCLI_SEVERITY_STR) {
                        const char *cmd = "set severity-output string -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                }
                if (pcli->flags & ACCESS_MCLI_SEVERITY_NB) {
                        const char *cmd = "set severity-output number -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                }
 
@@ -3457,11 +3472,17 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
                        goto end;
                } else if (pcli_has_level(s, ACCESS_LVL_OPER)) {
                        const char *cmd = "operator -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                } else if (pcli_has_level(s, ACCESS_LVL_USER)) {
                        const char *cmd = "user -;";
-                       ci_insert(req, 0, cmd, strlen(cmd));
+                       if (!ci_insert(req, 0, cmd, strlen(cmd))) {
+                               ret = -1;
+                               goto end;
+                       }
                        ret += strlen(cmd);
                }
        }