components: finsh: check token bounds before access

Move the command length checks before reading command buffers while parsing module, script, and LWP command names. This keeps commands without separators from reading one byte past the provided length.

Generated-by: OpenAI Codex
Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
This commit is contained in:
Old-Ding authored and Rbb666 committed 2026-07-08 13:37:21 +08:00
1 parent b9550aad85
commit 221502ade0
2 files changed
+3 -3

No files matched your search

+2 -2
View File
@@ -262,7 +262,7 @@ int msh_exec_module(const char *cmd_line, int size)
if (size == 0)
return -RT_ERROR;
/* get the length of command0 */
while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size)
while (cmd_length < size && cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t')
cmd_length ++;
/* get name length */
@@ -487,7 +487,7 @@ int _msh_exec_lwp(int debug, char *cmd, rt_size_t length)
int ret;
/* find the size of first command */
while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
while (cmd0_size < length && cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t')
cmd0_size ++;
if (cmd0_size == 0)
return -1;
+1 -1
View File
@@ -76,7 +76,7 @@ int msh_exec_script(const char *cmd_line, int size)
if (size == 0) return -RT_ERROR;
/* get the length of command0 */
while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size)
while (cmd_length < size && cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t')
cmd_length ++;
/* get name length */