From d3020e7eaa296e758ddbd69d0d11e0230b3fd31f Mon Sep 17 00:00:00 2001 From: Noah Date: Mon, 1 Jul 2024 17:18:37 -0500 Subject: [PATCH] Fix crash in cli_process if only spaces (delimiter char) are entered before CMD_TERMINATOR sent --- src/cli.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/cli.c b/src/cli.c index 5258918..0bbcc84 100644 --- a/src/cli.c +++ b/src/cli.c @@ -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); + } } }