From: Christopher Faulet Date: Wed, 29 Nov 2023 12:20:59 +0000 (+0100) Subject: BUG/MEDIUM: cli: Don't look for payload pattern on empty commands X-Git-Tag: v2.9-dev12~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9418366b4077da673b4d51653e0e599d212f70c;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: cli: Don't look for payload pattern on empty commands A regression was introduced by commit 9431aa0bdf ("BUG/MEDIUM: cli: Don't look for payload pattern on empty commands"). On empty commands (really empty or containing spaces and tabs), the number of arguments set to 0. However we look for the payload pattern without checking it. The result is an access at the index -1 in the argument array. It is of course invalid. To fix the issue, we just skip this part when there is no argument. Note that the empty command is still sent to the worker. This patch should solve the issue #2365. No backport needed. --- diff --git a/src/cli.c b/src/cli.c index efc55bc752..069a265932 100644 --- a/src/cli.c +++ b/src/cli.c @@ -2645,11 +2645,10 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int *p++ = 0; i++; } - argl = i; /* first look for '<<' at the beginning of the last argument */ - if (strncmp(args[argl-1], PAYLOAD_PATTERN, strlen(PAYLOAD_PATTERN)) == 0) { + if (argl && strncmp(args[argl-1], PAYLOAD_PATTERN, strlen(PAYLOAD_PATTERN)) == 0) { size_t pat_len = strlen(args[argl-1] + strlen(PAYLOAD_PATTERN)); /*