]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: allow the semi-colon to be escaped on the CLI
authorChad Lavoie <clavoie@haproxy.com>
Thu, 26 May 2016 20:42:25 +0000 (16:42 -0400)
committerWilly Tarreau <w@1wt.eu>
Tue, 30 Aug 2016 20:32:23 +0000 (22:32 +0200)
Today I was working on an auto-update script for some ACLs, and found
that I couldn't load ACL entries with a semi-colon in them no matter
how I tried to escape it.

As such, I wrote this patch (this one is for 1.7dev, but it applies to
1.5 the same with just line numbers changed), which seems to allow me
to execute a command such as "add acl /etc/foo.lst foo\;bar" over the
socket. It's worth noting that stats_sock_parse_request() already uses
the backslash to escape spaces in words so it makes sense to use it as
well to escape the semi-colon.

doc/management.txt
src/dumpstats.c

index d3a2e1a0e2a195032bcac98ea883408fd2a244b8..f559ffc8627fee7e0621acdda68b6826940afd47 100644 (file)
@@ -1239,6 +1239,9 @@ example :
 
     # echo "show info;show stat;show table" | socat /var/run/haproxy stdio
 
+If a command needs to use a semi-colon (eg: in a value), it must be preceeded
+by a backslash ('\').
+
 The interactive mode displays a prompt ('>') and waits for commands to be
 entered on the line, then processes them, and displays the prompt again to wait
 for a new command. This mode is entered via the "prompt" command which must be
index 6c8e3ee57b398645b85a62961515cb92cf51102b..b42c07aa9bcb41c1ed9b13ed43862e5364bdb047 100644 (file)
@@ -2656,15 +2656,20 @@ static void cli_io_handler(struct appctx *appctx)
                                continue;
                        }
 
-                       /* seek for a possible semi-colon. If we find one, we
-                        * replace it with an LF and skip only this part.
+                       /* seek for a possible unescaped semi-colon. If we find
+                        * one, we replace it with an LF and skip only this part.
                         */
-                       for (len = 0; len < reql; len++)
+                       for (len = 0; len < reql; len++) {
+                               if (trash.str[len] == '\\') {
+                                       len++;
+                                       continue;
+                               }
                                if (trash.str[len] == ';') {
                                        trash.str[len] = '\n';
                                        reql = len + 1;
                                        break;
                                }
+                       }
 
                        /* now it is time to check that we have a full line,
                         * remove the trailing \n and possibly \r, then cut the