Skip to content

Commit

Permalink
shell: fix index out bound issue
Browse files Browse the repository at this point in the history
In order to prevent index out of bounds access of the sh->ctx->cmd_buff
array when sh->ctx->cmd_buff_pos is 0, it has been added a check for the
value of sh->ctx->cmd_buff_pos.

This ensures that the array will not be accessed beyond its boundaries.

Signed-off-by: Jungo Lin <[email protected]>
  • Loading branch information
JungoLin1978 authored and carlescufi committed May 27, 2024
1 parent 512c183 commit fa716d9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions subsys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ static bool tab_prepare(const struct shell *sh,
/* If last command is not completed (followed by space) it is treated
* as uncompleted one.
*/
int space = isspace((int)sh->ctx->cmd_buff[
sh->ctx->cmd_buff_pos - 1]);
int space = (sh->ctx->cmd_buff_pos > 0) ?
isspace((int)sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos - 1]) : 0;

/* root command completion */
if ((*argc == 0) || ((space == 0) && (*argc == 1))) {
Expand Down

0 comments on commit fa716d9

Please sign in to comment.