From: Frediano Ziglio via Grub-devel <grub-devel@gnu.org>
To: grub-devel@gnu.org
Cc: Frediano Ziglio <frediano.ziglio@cloud.com>
Subject: [PATCH v2] loader/efi/linux: Correctly terminate LoadOptions field
Date: Tue, 24 Jun 2025 09:01:14 +0100 [thread overview]
Message-ID: <20250624080116.192089-1-frediano.ziglio@cloud.com> (raw)
If a simple string for arguments are passed it should be NUL
terminated. This is true for other code but not for "linux"
command.
Signed-off-by: Frediano Ziglio <frediano.ziglio@cloud.com>
---
Changes since v1
- remove useless assignment.
---
grub-core/loader/efi/linux.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
index 78ea07ca8..0c14f6d8f 100644
--- a/grub-core/loader/efi/linux.c
+++ b/grub-core/loader/efi/linux.c
@@ -190,7 +190,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
grub_efi_boot_services_t *b;
grub_efi_status_t status;
grub_efi_loaded_image_t *loaded_image;
- int len;
+ grub_size_t len;
mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
if (!mempath)
@@ -223,16 +223,17 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
grub_error (GRUB_ERR_BAD_FIRMWARE, "missing loaded_image proto");
goto unload;
}
- loaded_image->load_options_size = len =
- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
+ len = (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
loaded_image->load_options =
grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (len));
if (!loaded_image->load_options)
return grub_errno;
- loaded_image->load_options_size =
- 2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
- (grub_uint8_t *) args, len, NULL);
+ len = grub_utf8_to_utf16 (loaded_image->load_options, len,
+ (grub_uint8_t *) args, (grub_size_t) -1, NULL);
+ /* NUL terminate */
+ ((grub_efi_char16_t*)loaded_image->load_options)[len++] = 0;
+ loaded_image->load_options_size = len * sizeof (grub_efi_char16_t);
grub_dprintf ("linux", "starting image %p\n", image_handle);
status = b->start_image (image_handle, 0, NULL);
--
2.49.0
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next reply other threads:[~2025-06-24 8:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-24 8:01 Frediano Ziglio via Grub-devel [this message]
2025-06-24 15:48 ` [PATCH v2] loader/efi/linux: Correctly terminate LoadOptions field Daniel Kiper
2025-06-25 7:05 ` Frediano Ziglio via Grub-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250624080116.192089-1-frediano.ziglio@cloud.com \
--to=grub-devel@gnu.org \
--cc=frediano.ziglio@cloud.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.