From e1553d860dc42a819fe71913d5a68a77fbf64a6e Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Mon, 18 Oct 2021 01:23:07 -0400 Subject: Open_Plugin add checksum on struct offsets Adding a checksum over the struct offset will allow checking for compatibility across machines rather than using packed structs to ensure compability For any file created by the user from the device this isn't really a concern But for files between machines, across installs (sim v device), possibly even across compilers this at least will alert the user rather than returning junk data Change-Id: Id0531bbaa7013dce24dece270849f0a10ac99c20 --- apps/open_plugin.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'apps/open_plugin.h') diff --git a/apps/open_plugin.h b/apps/open_plugin.h index e1d49bf329..adfb9a75bc 100644 --- a/apps/open_plugin.h +++ b/apps/open_plugin.h @@ -41,19 +41,31 @@ enum { OPEN_PLUGIN_LANG_IGNORE = (-2), OPEN_PLUGIN_LANG_IGNOREALL = (-3), OPEN_PLUGIN_NOT_FOUND = (-1), - OPEN_PLUGIN_NEEDS_FLUSHED = (-2) + OPEN_PLUGIN_NEEDS_FLUSHED = (-2), }; struct open_plugin_entry_t { -/* hash and lang_id need to be the first items */ +/* hash lang_id checksum need to be the first items */ uint32_t hash; int32_t lang_id; + uint32_t checksum; char name[OPEN_PLUGIN_NAMESZ+1]; /*char key[OPEN_PLUGIN_BUFSZ+1];*/ char path[OPEN_PLUGIN_BUFSZ+1]; char param[OPEN_PLUGIN_BUFSZ+1]; -}__attribute__((packed)); +}; + +#define OPEN_PLUGIN_CHECKSUM (uint32_t) \ +( \ + (sizeof(struct open_plugin_entry_t) << 16) + \ + offsetof(struct open_plugin_entry_t, hash) + \ + offsetof(struct open_plugin_entry_t, lang_id) + \ + offsetof(struct open_plugin_entry_t, checksum) + \ + offsetof(struct open_plugin_entry_t, name) + \ + /*offsetof(struct open_plugin_entry_t, key)+*/ \ + offsetof(struct open_plugin_entry_t, path) + \ + offsetof(struct open_plugin_entry_t, param)) inline static void open_plugin_get_hash(const char *key, uint32_t *hash) { -- cgit v1.2.3