]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: cli: handle correctly prefix and payload
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 13 Dec 2018 08:05:48 +0000 (09:05 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Dec 2018 08:45:16 +0000 (09:45 +0100)
In the master CLI, the commands and the prefix were still parsed and
trimmed after the pattern payload. Don't parse anything but the end of a
line till we are in payload mode.

Put the search of the pattern after the trim so we can use correctly a
payload with a command which is prefixed by @.

src/cli.c

index 2299c1cf8698fbfa465509f772c1becd89b021d8..d75955d15fe4d27de2a83c7cb191302637a836bd 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1933,16 +1933,9 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
                return -1;
        }
 
-       /* last line of the payload */
-       if ((s->pcli_flags & PCLI_F_PAYLOAD) && (reql == 1)) {
-               s->pcli_flags &= ~PCLI_F_PAYLOAD;
-               return reql;
-       }
-
-       payload = strstr(p, PAYLOAD_PATTERN);
-       if ((end - 1) == (payload + strlen(PAYLOAD_PATTERN))) {
-               /* if the payload pattern is at the end */
-               s->pcli_flags |= PCLI_F_PAYLOAD;
+       if (s->pcli_flags & PCLI_F_PAYLOAD) {
+               if (reql == 1) /* last line of the payload */
+                       s->pcli_flags &= ~PCLI_F_PAYLOAD;
                return reql;
        }
 
@@ -1986,12 +1979,19 @@ int pcli_parse_request(struct stream *s, struct channel *req, char **errmsg, int
        /* End of words are ending by \0, we need to replace the \0s by spaces
 1         before forwarding them */
        p = str;
-       while (p < end) {
+       while (p < end-1) {
                if (*p == '\0')
                        *p = ' ';
                p++;
        }
 
+       payload = strstr(str, PAYLOAD_PATTERN);
+       if ((end - 1) == (payload + strlen(PAYLOAD_PATTERN))) {
+               /* if the payload pattern is at the end */
+               s->pcli_flags |= PCLI_F_PAYLOAD;
+               ret = reql;
+       }
+
        *(end-1) = '\n';
 
        if (wtrim > 0) {