Skip to contentSkip to conversation

loader/efi: Reuse len variable

PATCH In review Frediano Ziglio via Grub-devel 2 participants 3 messages Sep 3, 2024 – Sep 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 loader/efi: Reuse len variable

---
 grub-core/loader/efi/linux.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

---
Changes since v1:
- split pointer reset.

grub-core/loader/efi/linux.c +2 -2
index 803d2541d..cbb480b34 100644
@@ -226,7 +226,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
   loaded_image->load_options_size = len =
     (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
   loaded_image->load_options =
-    grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
+    grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (len));
   if (!loaded_image->load_options)
     return grub_errno;
 
@@ -240,7 +240,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
   /* When successful, not reached */
   grub_error (GRUB_ERR_BAD_OS, "start_image() returned 0x%" PRIxGRUB_EFI_UINTN_T, status);
   grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
-		       GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
+		       GRUB_EFI_BYTES_TO_PAGES (len));
 unload:
   b->unload_image (image_handle);
 
Signature · 7 lines
2.46.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH v2 2/2 loader/efi: Reset freed pointer

Avoid dangling pointer.
Code should not be reached but better safe than sorry.

---
 grub-core/loader/efi/linux.c | 1 +
 1 file changed, 1 insertion(+)
grub-core/loader/efi/linux.c +1 -0
index cbb480b34..1ffbcf9ce 100644
@@ -241,6 +241,7 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
   grub_error (GRUB_ERR_BAD_OS, "start_image() returned 0x%" PRIxGRUB_EFI_UINTN_T, status);
   grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
 		       GRUB_EFI_BYTES_TO_PAGES (len));
+  loaded_image->load_options = NULL;
 unload:
   b->unload_image (image_handle);
 
Signature · 7 lines
2.46.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel