diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index 5ba34d7ed..a0faa40ec 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -400,6 +400,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) { grub_efi_file_path_device_path_t *fp; grub_efi_uint16_t len; + grub_efi_char16_t *dup_name; *p++ = '/'; @@ -410,7 +411,16 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) while (len > 0 && fp->path_name[len - 1] == 0) len--; - p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); + dup_name = grub_malloc (len * sizeof (*dup_name)); + if (!dup_name) + { + grub_free (name); + return NULL; + } + p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, + grub_memcpy (dup_name, fp->path_name, len * sizeof (*dup_name)), + len); + grub_free (dup_name); } dp = GRUB_EFI_NEXT_DEVICE_PATH (dp); @@ -840,9 +850,20 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) fp = (grub_efi_file_path_device_path_t *) dp; buf = grub_malloc ((len - 4) * 2 + 1); if (buf) - *grub_utf16_to_utf8 (buf, fp->path_name, + { + grub_efi_char16_t *dup_name = grub_malloc (len - 4); + if (!dup_name) + { + grub_errno = GRUB_ERR_NONE; + grub_printf ("/File((null))"); + grub_free (buf); + break; + } + *grub_utf16_to_utf8 (buf, grub_memcpy (dup_name, fp->path_name, len - 4), (len - 4) / sizeof (grub_efi_char16_t)) - = '\0'; + = '\0'; + grub_free (dup_name); + } else grub_errno = GRUB_ERR_NONE; grub_printf ("/File(%s)", buf);