From ae891e201124c7937dad301739f83cbb296ead9a Mon Sep 17 00:00:00 2001 From: bernard Date: Thu, 16 Jan 2014 22:22:23 +0800 Subject: [PATCH] [Finsh] fix strncmp issue in command search --- components/finsh/msh.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 35ebb4b55..794fcb83e 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -166,7 +166,8 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; - if (strncmp(&index->name[6], cmd, size) == 0) + if (strncmp(&index->name[6], cmd, size) == 0 && + index->name[6 + size] == '\0') { cmd_func = (cmd_function_t)index->func; break; @@ -256,16 +257,14 @@ int msh_exec(char* cmd, rt_size_t length) int cmd0_size = 0; cmd_function_t cmd_func; - while(*cmd == ' ') - { - cmd++; - length--; - } + /* strim the beginning of command */ + while(*cmd == ' ' || *cmd == '\t'){cmd++; length--;} + /* find the size of first command */ while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length) cmd0_size ++; - + if (cmd0_size == 0) return -1; /* no command found */ + /* try to get built-in command */ - if (cmd0_size == 0) return -1; cmd_func = msh_get_cmd(cmd, cmd0_size); if (cmd_func == RT_NULL) {