Blob Blame History Raw
From 7514e0f35f08666aa0cd5edc2859104c19b7b2a1 Mon Sep 17 00:00:00 2001
From: Andreas Fuchs <andreas.fuchs@sit.fraunhofer.de>
Date: Thu, 13 Jan 2022 16:48:30 +0100
Subject: [PATCH 19/23] MU: Fix buffer upcast leading to misalignment

Signed-off-by: Andreas Fuchs <andreas.fuchs@sit.fraunhofer.de>
---
 src/tss2-mu/tpm2b-types.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/tss2-mu/tpm2b-types.c b/src/tss2-mu/tpm2b-types.c
index 6aa2feb3..2e10f487 100644
--- a/src/tss2-mu/tpm2b-types.c
+++ b/src/tss2-mu/tpm2b-types.c
@@ -208,8 +208,10 @@ TSS2_RC Tss2_MU_##type##_Marshal(type const *src, uint8_t buffer[], \
         return rc; \
 \
     /* Update the size to the real value */ \
-    if (buffer) \
-        *(UINT16 *)ptr = HOST_TO_BE_16(buffer + local_offset - ptr - 2); \
+    if (buffer) { \
+        UINT16 t = HOST_TO_BE_16(buffer + local_offset - ptr - 2); \
+        memcpy(ptr, &t, sizeof(t)); \
+    } \
 \
     if (offset != NULL) { \
         *offset = local_offset; \
-- 
2.34.3