Skip to content

Commit

Permalink
Fix crash in cli_process if only spaces (delimiter char) are entered …
Browse files Browse the repository at this point in the history
…before CMD_TERMINATOR sent
  • Loading branch information
ovylnoah committed Jul 1, 2024
1 parent 64bc81a commit d3020e7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ cli_status_t cli_process(cli_t *cli)
argv[++argc] = strtok(NULL, " ");
}

/* Search the command table for a matching command, using argv[0]
* which is the command name. */
for(size_t i = 0 ; i < cli->cmd_cnt ; i++)
{
if(strcmp(argv[0], cli->cmd_tbl[i].cmd) == 0)
if(argv[0] != NULL) {
/* Search the command table for a matching command, using argv[0]
* which is the command name. */
for(size_t i = 0 ; i < cli->cmd_cnt ; i++)
{
/* Found a match, execute the associated function. */
return cli->cmd_tbl[i].func(argc, argv);
if(strcmp(argv[0], cli->cmd_tbl[i].cmd) == 0)
{
/* Found a match, execute the associated function. */
return cli->cmd_tbl[i].func(argc, argv);
}
}
}

Expand Down

0 comments on commit d3020e7

Please sign in to comment.