]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cli: allow the backslash to be escaped on the CLI
authorDragan Dosen <ddosen@haproxy.com>
Thu, 24 Nov 2016 10:33:12 +0000 (11:33 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Dec 2016 13:23:41 +0000 (14:23 +0100)
In 1.5-dev20, commit 48bcfda ("MEDIUM: dumpstat: make the CLI parser
understand the backslash as an escape char") introduced support for
backslash on the CLI, but it strips all backslashes in all arguments
instead of only unescaping them, making it impossible to pass a
backslash in an argument.

This will allow us to use a backslash in a command over the socket, eg.
"add acl #0 ABC\\XYZ".

[wt: this should be backported to 1.7 and 1.6]

doc/management.txt
src/cli.c

index c8ba0e379e4a63b539b3b6af7be690799a146080..dd886dec7a3935b9ab73dedcb0851ecaf1e1a703 100644 (file)
@@ -1249,8 +1249,8 @@ 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 ('\').
+If a command needs to use a semi-colon or a backslash (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
index 239a505ad97a0cf3309c586c300c383ca39f3c4a..a1923bc4e71719c2bc0a2220f41fb31a5136dd4b 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -434,13 +434,17 @@ static int cli_parse_request(struct appctx *appctx, char *line)
        while (++arg <= MAX_STATS_ARGS)
                args[arg] = line;
 
-       /* remove \ */
+       /* unescape '\' */
        arg = 0;
        while (*args[arg] != '\0') {
                j = 0;
                for (i=0; args[arg][i] != '\0'; i++) {
-                       if (args[arg][i] == '\\')
-                               continue;
+                       if (args[arg][i] == '\\') {
+                               if (args[arg][i+1] == '\\')
+                                       i++;
+                               else
+                                       continue;
+                       }
                        args[arg][j] = args[arg][i];
                        j++;
                }