Skip to content

Commit c8e4aec

Browse files
committed
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>
1 parent 5882e6a commit c8e4aec

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

components/finsh/msh.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ int msh_exec_module(const char *cmd_line, int size)
262262
if (size == 0)
263263
return -RT_ERROR;
264264
/* get the length of command0 */
265-
while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size)
265+
while (cmd_length < size && cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t')
266266
cmd_length ++;
267267

268268
/* get name length */
@@ -487,7 +487,7 @@ int _msh_exec_lwp(int debug, char *cmd, rt_size_t length)
487487
int ret;
488488

489489
/* find the size of first command */
490-
while ((cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t') && cmd0_size < length)
490+
while (cmd0_size < length && cmd[cmd0_size] != ' ' && cmd[cmd0_size] != '\t')
491491
cmd0_size ++;
492492
if (cmd0_size == 0)
493493
return -1;

components/finsh/msh_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int msh_exec_script(const char *cmd_line, int size)
7676
if (size == 0) return -RT_ERROR;
7777

7878
/* get the length of command0 */
79-
while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size)
79+
while (cmd_length < size && cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t')
8080
cmd_length ++;
8181

8282
/* get name length */

0 commit comments

Comments
 (0)