]> git.proxmox.com Git - efi-boot-shim.git/commitdiff
Fix the broken bootpath
authorGary Ching-Pang Lin <glin@suse.com>
Thu, 21 Feb 2013 09:49:29 +0000 (17:49 +0800)
committerPeter Jones <pjones@redhat.com>
Thu, 26 Sep 2013 15:58:01 +0000 (11:58 -0400)
- The file path from DevicePathToStr may use slash as the file
  seperator. Change all slashes to backslashes to avoid the strange
  bootpath.
- Remove the redundant backslashes.
- ImagePath no longer requires the leading backslash.
- Fix a memory leak

Based on the patch from Michal Marek <mmarek@suse.com>

shim.c

diff --git a/shim.c b/shim.c
index d2ff51af3eb3325a877b6afdd54a8e4a27cdc9ec..5c7840664c50d5461e950cf9d299ec6999b26d5f 100644 (file)
--- a/shim.c
+++ b/shim.c
@@ -995,15 +995,25 @@ static EFI_STATUS generate_path(EFI_LOADED_IMAGE *li, CHAR16 *ImagePath,
 
        pathlen = StrLen(bootpath);
 
+       /*
+        * DevicePathToStr() concatenates two nodes with '/'.
+        * Convert '/' to '\\'.
+        */
+       for (i = 0; i < pathlen; i++) {
+               if (bootpath[i] == '/')
+                       bootpath[i] = '\\';
+       }
        for (i=pathlen; i>0; i--) {
-               if (bootpath[i] == '\\')
+               if (bootpath[i] == '\\' && bootpath[i-1] != '\\')
                        break;
        }
+       if (bootpath[i] == '\\')
+               bootpath[i+1] = '\0';
+       else
+               bootpath[0] = '\0';
 
-       bootpath[i+1] = '\0';
-
-       if (i == 0 || bootpath[i-i] == '\\')
-               bootpath[i] = '\0';
+       while (*ImagePath == '\\')
+               ImagePath++;
 
        *PathName = AllocatePool(StrSize(bootpath) + StrSize(ImagePath));
 
@@ -1021,6 +1031,8 @@ static EFI_STATUS generate_path(EFI_LOADED_IMAGE *li, CHAR16 *ImagePath,
        *grubpath = FileDevicePath(device, *PathName);
 
 error:
+       FreePool(bootpath);
+
        return efi_status;
 }