From 166dfcbbeed348bbdb4798818e24bc99239a2aaf Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Mon, 4 May 2026 19:00:27 +0200 Subject: [PATCH] BUG/MINOR: mworker/cli: check ci_insert() return value in pcli_parse_request() 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 | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/cli.c b/src/cli.c index 62158f2d6..cab99aa33 100644 --- 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); } }