From 3e750e8419ff2ad1a7eb46d6d7a2a2b88d2d7be4 Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Thu, 1 Dec 2022 14:22:23 +0100 Subject: [PATCH] Fix device crash caused by improper memory alignment of the plugin context buffer --- src/shared_context.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/shared_context.h b/src/shared_context.h index 54c7566..414586c 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -65,7 +65,9 @@ typedef struct tokenContext_t { uint8_t contractAddress[ADDRESS_LENGTH]; uint8_t methodSelector[SELECTOR_LENGTH]; }; - uint8_t pluginContext[5 * INT256_LENGTH]; + // This needs to be strictly 4 bytes aligned since pointers to it will be casted as + // plugin context struct pointers (structs that contain up to 4 bytes wide elements) + uint8_t pluginContext[5 * INT256_LENGTH] __attribute__((aligned(4))); }; #ifdef HAVE_STARKWARE @@ -77,6 +79,8 @@ typedef struct tokenContext_t { } tokenContext_t; +_Static_assert((offsetof(tokenContext_t, pluginContext) % 4) == 0, "Plugin context not aligned"); + typedef struct publicKeyContext_t { cx_ecfp_public_key_t publicKey; char address[41];