diff options
| author | bernard <[email protected]> | 2014-01-16 22:22:23 +0800 |
|---|---|---|
| committer | bernard <[email protected]> | 2014-01-16 22:22:23 +0800 |
| commit | ae891e201124c7937dad301739f83cbb296ead9a (patch) | |
| tree | 9871e53d2c38484adee9f981fdd70410ef46e2c9 | |
| parent | 2970723cb03191f2b756ef5f5e18ce093cc0ca3c (diff) | |
[Finsh] fix strncmp issue in command search
| -rw-r--r-- | components/finsh/msh.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 35ebb4b559..794fcb83e8 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) { |
