]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Drop use of DuplicateDevicePath 23589/head
authorJan Janssen <medhefgo@web.de>
Sun, 29 May 2022 09:08:40 +0000 (11:08 +0200)
committerJan Janssen <medhefgo@web.de>
Thu, 9 Jun 2022 10:50:13 +0000 (12:50 +0200)
src/boot/efi/xbootldr.c

index ade2e7f3d377448bdd1443570baf1b8ca59d6dc2..6e60e4b45df33b60f55d15032b3fe65a68c46d87 100644 (file)
@@ -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;