From: Kinsey Moore Date: Thu, 15 Aug 2013 16:21:20 +0000 (+0000) Subject: Remove leading spaces from the CLI command before parsing X-Git-Tag: 1.8.24.0-rc1~47 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de024296c14e3881cf7a578f9d7e5a61704db04b;p=thirdparty%2Fasterisk.git Remove leading spaces from the CLI command before parsing If you've mistakenly put a space before typing in a command, the leading space will be included as part of the command, and the command parser will not find the corresponding command. This patch rectifies that situation by stripping the leading spaces on commands. Review: https://reviewboard.asterisk.org/r/2709/ Patch-by: Tilghman Lesher git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@396745 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/asterisk.c b/main/asterisk.c index adf44be941..e164a3ff94 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1943,6 +1943,10 @@ static int remoteconsolehandler(char *s) ast_safe_system(getenv("SHELL") ? getenv("SHELL") : "/bin/sh"); ret = 1; } + while (isspace(*s)) { + s++; + } + if ((strncasecmp(s, "quit", 4) == 0 || strncasecmp(s, "exit", 4) == 0) && (s[4] == '\0' || isspace(s[4]))) { quit_handler(0, SHUTDOWN_FAST, 0); diff --git a/main/cli.c b/main/cli.c index 751974485d..a8533857eb 100644 --- a/main/cli.c +++ b/main/cli.c @@ -2282,6 +2282,13 @@ static char *parse_args(const char *s, int *argc, const char *argv[], int max, i return NULL; cur = duplicate; + + /* Remove leading spaces from the command */ + while (isspace(*s)) { + cur++; + s++; + } + /* scan the original string copying into cur when needed */ for (; *s ; s++) { if (x >= max - 1) {