From 55233913c808ecc963eb5edf1062871bdc557b48 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Sun, 29 May 2022 11:08:40 +0200 Subject: [PATCH] boot: Drop use of DuplicateDevicePath --- src/boot/efi/xbootldr.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/boot/efi/xbootldr.c b/src/boot/efi/xbootldr.c index ade2e7f3d37..6e60e4b45df 100644 --- a/src/boot/efi/xbootldr.c +++ b/src/boot/efi/xbootldr.c @@ -25,6 +25,22 @@ static EFI_DEVICE_PATH *path_chop(EFI_DEVICE_PATH *path, EFI_DEVICE_PATH *node) return chopped; } +static EFI_DEVICE_PATH *path_dup(const EFI_DEVICE_PATH *dp) { + assert(dp); + + const EFI_DEVICE_PATH *node = dp; + size_t size = 0; + while (!IsDevicePathEnd(node)) { + size += DevicePathNodeLength(node); + node = NextDevicePathNode(node); + } + size += DevicePathNodeLength(node); + + EFI_DEVICE_PATH *dup = xmalloc(size); + memcpy(dup, dp, size); + return dup; +} + static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_expected) { EFI_PARTITION_TABLE_HEADER *h; UINT32 crc32, crc32_saved; @@ -227,7 +243,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p } /* Patch in the data we found */ - EFI_DEVICE_PATH *xboot_path = ASSERT_SE_PTR(DuplicateDevicePath(partition_path)); + EFI_DEVICE_PATH *xboot_path = path_dup(partition_path); memcpy((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd)); *ret_device_path = xboot_path; return EFI_SUCCESS; -- 2.47.3