Skip to content

Commit fa716d9

Browse files
JungoLin1978carlescufi
authored andcommitted
shell: fix index out bound issue
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]>
1 parent 512c183 commit fa716d9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

subsys/shell/shell.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ static bool tab_prepare(const struct shell *sh,
288288
/* If last command is not completed (followed by space) it is treated
289289
* as uncompleted one.
290290
*/
291-
int space = isspace((int)sh->ctx->cmd_buff[
292-
sh->ctx->cmd_buff_pos - 1]);
291+
int space = (sh->ctx->cmd_buff_pos > 0) ?
292+
isspace((int)sh->ctx->cmd_buff[sh->ctx->cmd_buff_pos - 1]) : 0;
293293

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

0 commit comments

Comments
 (0)