From: Jan Janssen Date: Sun, 29 May 2022 09:08:40 +0000 (+0200) Subject: boot: Drop use of DuplicateDevicePath X-Git-Tag: v252-rc1~835^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F23589%2Fhead;p=thirdparty%2Fsystemd.git boot: Drop use of DuplicateDevicePath --- 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;