Skip to content

Commit

Permalink
settings: shell: Fix possible buffer overflow
Browse files Browse the repository at this point in the history
Checks the size of the given string before copying it to internal
buffer.

Signed-off-by: Flavio Ceolin <[email protected]>
  • Loading branch information
Flavio Ceolin authored and carlescufi committed Dec 15, 2023
1 parent e70a1a0 commit 8977784
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions subsys/settings/src/settings_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ static int cmd_write(const struct shell *shell_ptr, size_t argc, char *argv[])
break;
case SETTINGS_VALUE_STRING:
buffer_len = strlen(argv[argc - 1]) + 1;
if (buffer_len > sizeof(buffer)) {
shell_error(shell_ptr, "%s is bigger than shell's buffer", argv[argc - 1]);
return -EINVAL;
}

memcpy(buffer, argv[argc - 1], buffer_len);
break;
}
Expand Down

0 comments on commit 8977784

Please sign in to comment.