summaryrefslogtreecommitdiffstats
path: root/src/boot/efi/disk.c
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-05-29 10:33:42 +0200
committerJan Janssen <medhefgo@web.de>2022-06-09 12:50:13 +0200
commitb04f818417866d2781bd0be7820b506232ecfc2c (patch)
treea4efe8d3d5a5755a42b825506f2ffc78e7630e88 /src/boot/efi/disk.c
parentboot: Drop use of FileDevicePath (diff)
downloadsystemd-b04f818417866d2781bd0be7820b506232ecfc2c.tar.xz
systemd-b04f818417866d2781bd0be7820b506232ecfc2c.zip
boot: Drop use of UnpackDevicePath
Device paths are a packed data structure and the UEFI spec is clear that members may be misaligned. In this case all accesses are aligned except for the signature. We can simply memcpy it instead of making a whole (aligned) copy of the device path.
Diffstat (limited to '')
-rw-r--r--src/boot/efi/disk.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/boot/efi/disk.c b/src/boot/efi/disk.c
index fcd5812ff1..bf2984ed1f 100644
--- a/src/boot/efi/disk.c
+++ b/src/boot/efi/disk.c
@@ -8,31 +8,32 @@
EFI_STATUS disk_get_part_uuid(EFI_HANDLE *handle, CHAR16 uuid[static 37]) {
EFI_STATUS err;
- EFI_DEVICE_PATH *device_path;
- _cleanup_freepool_ EFI_DEVICE_PATH *paths = NULL;
+ EFI_DEVICE_PATH *dp;
/* export the device path this image is started from */
if (!handle)
return EFI_NOT_FOUND;
- err = BS->HandleProtocol(handle, &DevicePathProtocol, (void **) &device_path);
+ err = BS->HandleProtocol(handle, &DevicePathProtocol, (void **) &dp);
if (err != EFI_SUCCESS)
return err;
- paths = UnpackDevicePath(device_path);
- for (EFI_DEVICE_PATH *path = paths; !IsDevicePathEnd(path); path = NextDevicePathNode(path)) {
- HARDDRIVE_DEVICE_PATH *drive;
-
- if (DevicePathType(path) != MEDIA_DEVICE_PATH)
+ for (; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
+ if (DevicePathType(dp) != MEDIA_DEVICE_PATH)
continue;
- if (DevicePathSubType(path) != MEDIA_HARDDRIVE_DP)
+ if (DevicePathSubType(dp) != MEDIA_HARDDRIVE_DP)
continue;
- drive = (HARDDRIVE_DEVICE_PATH *)path;
- if (drive->SignatureType != SIGNATURE_TYPE_GUID)
+
+ HARDDRIVE_DEVICE_PATH *hd = (HARDDRIVE_DEVICE_PATH *) dp;
+ if (hd->SignatureType != SIGNATURE_TYPE_GUID)
continue;
- GuidToString(uuid, (EFI_GUID *)&drive->Signature);
+ /* Use memcpy in case the device path node is misaligned. */
+ EFI_GUID sig;
+ memcpy(&sig, hd->Signature, sizeof(hd->Signature));
+
+ GuidToString(uuid, &sig);
return EFI_SUCCESS;
}