From 899f8e8dc1f79a49b44f263428009c3509bb6054 Mon Sep 17 00:00:00 2001 From: Vladimir Serbinenko Date: Sat, 18 Jan 2014 16:41:47 +0100 Subject: Fix UEFI boot failure with some firmware that returns incorrect paths * grub-core/kern/efi/efi.c: Ensure that the result starts with / and has no //. Origin: upstream, http://git.savannah.gnu.org/cgit/grub.git/commit/?id=7e7293d745ef7c0a13d8cbf12f474843edfdd0ab Bug-Debian: https://bugs.debian.org/735960 Last-Update: 2015-03-23 Patch-Name: efi_sanitise_path.patch --- grub-core/kern/efi/efi.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index db0fd2d..3b6cf26 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -337,7 +337,7 @@ grub_efi_modules_addr (void) char * grub_efi_get_filename (grub_efi_device_path_t *dp0) { - char *name = 0, *p; + char *name = 0, *p, *pi; grub_size_t filesize = 0; grub_efi_device_path_t *dp; @@ -356,7 +356,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) grub_efi_uint16_t len; len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) / sizeof (grub_efi_char16_t)); - filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 1; + filesize += GRUB_MAX_UTF8_PER_UTF16 * len + 2; } dp = GRUB_EFI_NEXT_DEVICE_PATH (dp); @@ -384,12 +384,12 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) grub_efi_file_path_device_path_t *fp; grub_efi_uint16_t len; - if (p != name) - *p++ = '/'; + *p++ = '/'; len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) / sizeof (grub_efi_char16_t)); fp = (grub_efi_file_path_device_path_t *) dp; + p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); } @@ -398,10 +398,19 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) *p = '\0'; - /* EFI breaks paths with backslashes. */ - for (p = name; *p; p++) - if (*p == '\\') - *p = '/'; + for (pi = name, p = name; *pi;) + { + /* EFI breaks paths with backslashes. */ + if (*pi == '\\' || *pi == '/') + { + *p++ = '/'; + while (*pi == '\\' || *pi == '/') + pi++; + continue; + } + *p++ = *pi++; + } + *p = '\0'; return name; }