From: Chad Lavoie Date: Thu, 26 May 2016 20:42:25 +0000 (-0400) Subject: MINOR: cli: allow the semi-colon to be escaped on the CLI X-Git-Tag: v1.7-dev5~56 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e3f5031b5186367d8559dad5170cf88bff923a04;p=thirdparty%2Fhaproxy.git MINOR: cli: allow the semi-colon to be escaped on the CLI 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. --- diff --git a/doc/management.txt b/doc/management.txt index d3a2e1a0e2..f559ffc862 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -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 diff --git a/src/dumpstats.c b/src/dumpstats.c index 6c8e3ee57b..b42c07aa9b 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -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