Fix device crash caused by improper memory alignment of the plugin context buffer
@@ -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];
