summaryrefslogtreecommitdiff
path: root/src/common/console.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2019-10-18 15:58:21 +0200
committerHaru <haru@dotalux.com>2019-10-18 18:14:27 +0200
commitf174b0c7067be290a00882e09746d8a51d46f9c0 (patch)
tree34e0509ff0352a5b40d3462aac8c75d9e9b31a80 /src/common/console.c
parent2f27b0ae1528bc37a18d8137ec26bb782e5c38a4 (diff)
downloadhercules-f174b0c7067be290a00882e09746d8a51d46f9c0.tar.gz
hercules-f174b0c7067be290a00882e09746d8a51d46f9c0.tar.bz2
hercules-f174b0c7067be290a00882e09746d8a51d46f9c0.tar.xz
hercules-f174b0c7067be290a00882e09746d8a51d46f9c0.zip
Fix some issues with the strtok output in the console command parser
- Fixes a crash in the console command parser when a line consisting only of spaces is executed. - Fixes some extra spaces accidentally passed at the beginning of the argument string to console commands, if the input started with multiple adjacent spaces. Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/common/console.c')
-rw-r--r--src/common/console.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/common/console.c b/src/common/console.c
index a990d86b3..0075ac2a1 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -322,6 +322,7 @@ static void console_parse_create(char *name, CParseFunc func)
nullpo_retv(name);
safestrncpy(sublist, name, CP_CMD_LENGTH * 5);
tok = strtok(sublist,":");
+ nullpo_retv(tok);
ARR_FIND(0, VECTOR_LENGTH(console->input->command_list), i, strcmpi(tok, VECTOR_INDEX(console->input->command_list, i)->cmd) == 0);
@@ -404,6 +405,10 @@ static void console_parse_sub(char *line)
nullpo_retv(line);
memcpy(bline, line, 200);
tok = strtok(line, " ");
+ if (tok == NULL) {
+ // Ignore empty commands
+ return;
+ }
ARR_FIND(0, VECTOR_LENGTH(console->input->command_list), i, strcmpi(tok, VECTOR_INDEX(console->input->command_list, i)->cmd) == 0);
if (i == VECTOR_LENGTH(console->input->command_list)) {
@@ -417,6 +422,12 @@ static void console_parse_sub(char *line)
if (cmd->type == CPET_FUNCTION) {
tok = strtok(NULL, "");
+ if (tok != NULL) {
+ while (tok[0] == ' ')
+ tok++;
+ if (tok[0] == '\0')
+ tok = NULL;
+ }
cmd->u.func(tok);
return;
}
@@ -444,6 +455,12 @@ static void console_parse_sub(char *line)
entry = VECTOR_INDEX(cmd->u.children, i);
if (entry->type == CPET_FUNCTION) {
tok = strtok(NULL, "");
+ if (tok != NULL) {
+ while (tok[0] == ' ')
+ tok++;
+ if (tok[0] == '\0')
+ tok = NULL;
+ }
entry->u.func(tok);
return;
}