Skip to content

Commit 8a8a323

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/libstub: Handle unterminated cmdline
Make the command line parsing more robust, by handling the case it is not NUL-terminated. Use strnlen instead of strlen, and make sure that the temporary copy is NUL-terminated before parsing. Cc: <[email protected]> Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent a37ca6a commit 8a8a323

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ efi_status_t efi_parse_options(char const *cmdline)
194194
if (!cmdline)
195195
return EFI_SUCCESS;
196196

197-
len = strlen(cmdline) + 1;
197+
len = strnlen(cmdline, COMMAND_LINE_SIZE - 1) + 1;
198198
status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, len, (void **)&buf);
199199
if (status != EFI_SUCCESS)
200200
return status;
201201

202-
str = skip_spaces(memcpy(buf, cmdline, len));
202+
memcpy(buf, cmdline, len - 1);
203+
buf[len - 1] = '\0';
204+
str = skip_spaces(buf);
203205

204206
while (*str) {
205207
char *param, *val;

0 commit comments

Comments
 (0)