]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: allow building sd-boot with -Werror=flex-array-member-not-at-end
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 3 Apr 2025 16:14:10 +0000 (01:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Apr 2025 11:54:53 +0000 (20:54 +0900)
src/boot/measure.c
src/boot/proto/tcg.h

index 15f1ba9afffa087c6ab7584219d678fb86700169..48e9fb5fc50b2423ccace15d8716846a28942c47 100644 (file)
@@ -18,10 +18,10 @@ static EFI_STATUS tpm2_measure_to_pcr_and_tagged_event_log(
                 uint32_t event_id,
                 const char16_t *description) {
 
-        _cleanup_free_ struct event {
+        _cleanup_free_ union event {
                 EFI_TCG2_EVENT tcg_event;
                 EFI_TCG2_TAGGED_EVENT tcg_tagged_event;
-        } _packed_ *event = NULL;
+        } *event = NULL;
         size_t desc_len, event_size;
 
         assert(tcg);
@@ -30,21 +30,17 @@ static EFI_STATUS tpm2_measure_to_pcr_and_tagged_event_log(
         /* New style stuff we log as EV_EVENT_TAG with a recognizable event tag. */
 
         desc_len = strsize16(description);
-        event_size = offsetof(EFI_TCG2_EVENT, Event) + offsetof(EFI_TCG2_TAGGED_EVENT, Event) + desc_len;
+        event_size = offsetof(EFI_TCG2_TAGGED_EVENT, Event) + desc_len;
 
         event = xmalloc(event_size);
-        *event = (struct event) {
-                .tcg_event = (EFI_TCG2_EVENT) {
-                        .Size = event_size,
-                        .Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER),
-                        .Header.HeaderVersion = EFI_TCG2_EVENT_HEADER_VERSION,
-                        .Header.PCRIndex = pcrindex,
-                        .Header.EventType = EV_EVENT_TAG,
-                },
-                .tcg_tagged_event = {
-                        .EventId = event_id,
-                        .EventSize = desc_len,
-                },
+        event->tcg_tagged_event = (EFI_TCG2_TAGGED_EVENT) {
+                .Size = event_size,
+                .Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER),
+                .Header.HeaderVersion = EFI_TCG2_EVENT_HEADER_VERSION,
+                .Header.PCRIndex = pcrindex,
+                .Header.EventType = EV_EVENT_TAG,
+                .EventId = event_id,
+                .EventSize = desc_len,
         };
         memcpy(event->tcg_tagged_event.Event, description, desc_len);
 
index e243bf8b72b7ed505055dfc4d0d90674a1fbd907..a85288178cd0d400b00118ee087d3973ecfdd767 100644 (file)
@@ -59,6 +59,8 @@ typedef struct {
 } _packed_ EFI_TCG2_EVENT;
 
 typedef struct {
+        uint32_t Size;
+        EFI_TCG2_EVENT_HEADER Header;
         uint32_t EventId;
         uint32_t EventSize;
         uint8_t Event[];