]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efi-api: cast before shift
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 28 Jul 2025 17:00:44 +0000 (02:00 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 4 Aug 2025 15:42:06 +0000 (16:42 +0100)
Fixes the following error when running with sanitizers:
```
TEST-87-AUX-UTILS-VM.sh[670]: + bootctl install --make-entry-directory=yes
TEST-87-AUX-UTILS-VM.sh[695]: Copied "/usr/lib/systemd/boot/efi/systemd-bootx64.efi.signed" to "/boot/EFI/systemd/systemd-bootx64.efi".
TEST-87-AUX-UTILS-VM.sh[695]: Copied "/usr/lib/systemd/boot/efi/systemd-bootx64.efi.signed" to "/boot/EFI/BOOT/BOOTX64.EFI".
TEST-87-AUX-UTILS-VM.sh[695]: Created "/boot/fedora".
TEST-87-AUX-UTILS-VM.sh[695]: Random seed file /boot/loader/random-seed successfully refreshed (32 bytes).
TEST-87-AUX-UTILS-VM.sh[695]: ../src/shared/efi-api.c:618:38: runtime error: left shift of 243 by 24 places cannot be represented in type 'int'
```

(cherry picked from commit be876c5933a5eb223565e70773746a4b49d49c9f)

src/shared/efi-api.c

index 37720f896b4297a56d3d6b99acc184cb1aec5b78..fea46d65688cab8ba914664b51fe07466d256207 100644 (file)
@@ -548,9 +548,9 @@ void efi_id128_to_guid(sd_id128_t id, void *ret_guid) {
         assert(ret_guid);
 
         EFI_GUID uuid = {
-                .Data1 = id.bytes[0] << 24 | id.bytes[1] << 16 | id.bytes[2] << 8 | id.bytes[3],
-                .Data2 = id.bytes[4] << 8 | id.bytes[5],
-                .Data3 = id.bytes[6] << 8 | id.bytes[7],
+                .Data1 = (uint32_t) id.bytes[0] << 24 | (uint32_t) id.bytes[1] << 16 | (uint32_t) id.bytes[2] << 8 | id.bytes[3],
+                .Data2 = (uint16_t) id.bytes[4] << 8 | id.bytes[5],
+                .Data3 = (uint16_t) id.bytes[6] << 8 | id.bytes[7],
         };
         memcpy(uuid.Data4, id.bytes+8, sizeof(uuid.Data4));
         memcpy(ret_guid, &uuid, sizeof(uuid));