Skip to content

Commit

Permalink
hdt: Fixing argv usage to avoid crash
Browse files Browse the repository at this point in the history
argv shall be passed as a pointer to avoid a crash when running
command like "dmi".

Thanks genec for pointing this out.
  • Loading branch information
ErwanAliasr1 committed Sep 4, 2015
1 parent 8f17572 commit 5c6e28d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions com32/hdt/hdt-cli.c
Expand Up @@ -322,7 +322,7 @@ static void expand_aliases(char *line __unused, char **command, char **module,
* command is always malloc'ed (even for an empty line)
**/
static void parse_command_line(char *line, char **command, char **module,
int *argc, char **argv)
int *argc, char ***argv)
{
int argc_iter = 0, args_pos = 0, token_found = 0, token_len = 0;
int args_len = 0;
Expand Down Expand Up @@ -390,8 +390,8 @@ static void parse_command_line(char *line, char **command, char **module,
pch = strtok(line + args_pos, CLI_SPACE);
while (pch != NULL) {
dprintf("CLI DEBUG parse: argv[%d] = %s\n", argc_iter, pch);
argv[argc_iter] = malloc(strlen(pch) * sizeof(char));
strlcpy(argv[argc_iter], pch, strlen(pch));
*argv[argc_iter] = malloc(strlen(pch) * sizeof(char));
strlcpy(*argv[argc_iter], pch, strlen(pch));
argc_iter++;
pch = strtok(NULL, CLI_SPACE);
/*
Expand Down Expand Up @@ -582,7 +582,7 @@ static void autocomplete(char *line)
char *command = NULL, *module = NULL;
char **argv = NULL;

parse_command_line(line, &command, &module, &argc, argv);
parse_command_line(line, &command, &module, &argc, &argv);

dprintf("CLI DEBUG autocomplete: before checking args\n");
/* If the user specified arguments, there is nothing we can complete */
Expand Down Expand Up @@ -623,7 +623,7 @@ static void exec_command(char *line, struct s_hardware *hardware)
struct cli_callback_descr *current_module = NULL;

/* This will allocate memory for command and module */
parse_command_line(line, &command, &module, &argc, argv);
parse_command_line(line, &command, &module, &argc, &argv);

dprintf("CLI DEBUG exec: Checking for aliases\n");
/*
Expand Down

0 comments on commit 5c6e28d

Please sign in to comment.