mirror of
https://git.proxmox.com/git/efi-boot-shim
synced 2025-07-26 01:55:27 +00:00
Make path generation more sensible
This commit is contained in:
parent
8c173876d1
commit
d3ee0bed5e
70
shim.c
70
shim.c
@ -688,39 +688,26 @@ static EFI_STATUS generate_path(EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **grubpath
|
|||||||
{
|
{
|
||||||
EFI_DEVICE_PATH *devpath;
|
EFI_DEVICE_PATH *devpath;
|
||||||
EFI_HANDLE device;
|
EFI_HANDLE device;
|
||||||
FILEPATH_DEVICE_PATH *FilePath;
|
int i;
|
||||||
int len;
|
|
||||||
unsigned int pathlen = 0;
|
unsigned int pathlen = 0;
|
||||||
EFI_STATUS efi_status = EFI_SUCCESS;
|
EFI_STATUS efi_status = EFI_SUCCESS;
|
||||||
|
CHAR16 *bootpath;
|
||||||
|
|
||||||
device = li->DeviceHandle;
|
device = li->DeviceHandle;
|
||||||
devpath = li->FilePath;
|
devpath = li->FilePath;
|
||||||
|
|
||||||
while (!IsDevicePathEnd(devpath) &&
|
bootpath = DevicePathToStr(devpath);
|
||||||
!IsDevicePathEnd(NextDevicePathNode(devpath))) {
|
|
||||||
FilePath = (FILEPATH_DEVICE_PATH *)devpath;
|
|
||||||
len = StrLen(FilePath->PathName);
|
|
||||||
|
|
||||||
pathlen += len;
|
pathlen = StrLen(bootpath);
|
||||||
|
|
||||||
if (len == 1 && FilePath->PathName[0] == '\\') {
|
for (i=pathlen; i>0; i--) {
|
||||||
devpath = NextDevicePathNode(devpath);
|
if (bootpath[i] == '\\')
|
||||||
continue;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
/* If no leading \, need to add one */
|
|
||||||
if (FilePath->PathName[0] != '\\')
|
|
||||||
pathlen++;
|
|
||||||
|
|
||||||
/* If trailing \, need to strip it */
|
|
||||||
if (FilePath->PathName[len-1] == '\\')
|
|
||||||
pathlen--;
|
|
||||||
|
|
||||||
devpath = NextDevicePathNode(devpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*PathName = AllocatePool(pathlen + StrLen(SECOND_STAGE));
|
bootpath[i+1] = '\0';
|
||||||
*PathName[0] = '\0';
|
|
||||||
|
*PathName = AllocatePool(StrSize(bootpath) + StrSize(SECOND_STAGE));
|
||||||
|
|
||||||
if (!*PathName) {
|
if (!*PathName) {
|
||||||
Print(L"Failed to allocate path buffer\n");
|
Print(L"Failed to allocate path buffer\n");
|
||||||
@ -728,41 +715,8 @@ static EFI_STATUS generate_path(EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **grubpath
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
devpath = li->FilePath;
|
*PathName[0] = '\0';
|
||||||
|
StrCat(*PathName, bootpath);
|
||||||
while (!IsDevicePathEnd(devpath) &&
|
|
||||||
!IsDevicePathEnd(NextDevicePathNode(devpath))) {
|
|
||||||
CHAR16 *tmpbuffer;
|
|
||||||
FilePath = (FILEPATH_DEVICE_PATH *)devpath;
|
|
||||||
len = StrLen(FilePath->PathName);
|
|
||||||
|
|
||||||
if (len == 1 && FilePath->PathName[0] == '\\') {
|
|
||||||
devpath = NextDevicePathNode(devpath);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpbuffer = AllocatePool(len + 1);
|
|
||||||
|
|
||||||
if (!tmpbuffer) {
|
|
||||||
Print(L"Unable to allocate temporary buffer\n");
|
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
StrCpy(tmpbuffer, FilePath->PathName);
|
|
||||||
|
|
||||||
/* If no leading \, need to add one */
|
|
||||||
if (tmpbuffer[0] != '\\')
|
|
||||||
StrCat(*PathName, L"\\");
|
|
||||||
|
|
||||||
/* If trailing \, need to strip it */
|
|
||||||
if (tmpbuffer[len-1] == '\\')
|
|
||||||
tmpbuffer[len=1] = '\0';
|
|
||||||
|
|
||||||
StrCat(*PathName, tmpbuffer);
|
|
||||||
FreePool(tmpbuffer);
|
|
||||||
devpath = NextDevicePathNode(devpath);
|
|
||||||
}
|
|
||||||
|
|
||||||
StrCat(*PathName, SECOND_STAGE);
|
StrCat(*PathName, SECOND_STAGE);
|
||||||
|
|
||||||
*grubpath = FileDevicePath(device, *PathName);
|
*grubpath = FileDevicePath(device, *PathName);
|
||||||
|
Loading…
Reference in New Issue
Block a user