1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

sys/shell: fix missing NULL terminator

This patch adds the missing NULL terminator to the argv passed to shell
command handlers. Without it, Newlib's getop() was intermittently
causing hardfaults. Closer inspection of NewLib's code revealed that it
relies in this NULL termination. ANSI-C also requires it of the argv
passed to main().
This commit is contained in:
Joshua DeWeese 2023-12-21 15:42:55 -05:00
parent 8a9dd047be
commit 5cd52885c1

View File

@ -305,7 +305,9 @@ static void handle_input_line(const shell_command_t *command_list, char *line)
/* then we fill the argv array */
int collected;
char *argv[argc];
/* allocate argv on the stack leaving space for NULL termination */
char *argv[argc + 1];
readpos = line;
for (collected = 0; collected < argc; collected++) {
@ -313,6 +315,10 @@ static void handle_input_line(const shell_command_t *command_list, char *line)
readpos += strlen(readpos) + 1;
}
/* NULL terminate argv. See `shell_command_handler_t` doc in shell.h for
rationale. */
argv[argc] = NULL;
/* then we call the appropriate handler */
shell_command_handler_t handler = find_handler(command_list, argv[0]);
if (handler != NULL) {