From b547f3eb92b76d5ff7e277f73b42e3cc24465a99 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 4 Apr 2025 01:14:10 +0900 Subject: [PATCH] boot: allow building sd-boot with -Werror=flex-array-member-not-at-end --- src/boot/measure.c | 26 +++++++++++--------------- src/boot/proto/tcg.h | 2 ++ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/boot/measure.c b/src/boot/measure.c index 15f1ba9afff..48e9fb5fc50 100644 --- a/src/boot/measure.c +++ b/src/boot/measure.c @@ -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); diff --git a/src/boot/proto/tcg.h b/src/boot/proto/tcg.h index e243bf8b72b..a85288178cd 100644 --- a/src/boot/proto/tcg.h +++ b/src/boot/proto/tcg.h @@ -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[]; -- 2.47.3