From 3f5ae99e42dd227c34ce3c11f74013b51826bfee Mon Sep 17 00:00:00 2001 From: Terry Ellison Date: Sun, 24 Mar 2019 22:47:29 +0000 Subject: [PATCH] Fix unaligned load/store exception in luaR_findentry (#2702) --- app/lua/lrotable.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/lua/lrotable.c b/app/lua/lrotable.c index 031c6217b5..3ee3e5f7fe 100644 --- a/app/lua/lrotable.c +++ b/app/lua/lrotable.c @@ -86,6 +86,7 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { size_t hash = HASH(rotable, key); unsigned i = 0; int j = lookup_cache(hash, rotable); + unsigned l = key ? key->tsv.len : sizeof("__metatable")-1; if (pentry) { if (j >= 0){ @@ -101,9 +102,9 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) { * aren't needed if there is a cache hit. Note that the termination null * is included so a "on\0" has a mask of 0xFFFFFF and "a\0" has 0xFFFF. */ - unsigned name4 = *(unsigned *)strkey; - unsigned l = key ? key->tsv.len : sizeof("__metatable")-1; - unsigned mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); + unsigned name4, mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8); + c_memcpy(&name4, strkey, sizeof(name4)); + for(;pentry->key.type != LUA_TNIL; i++, pentry++) { if ((pentry->key.type == LUA_TSTRING) && ((*(unsigned *)pentry->key.id.strkey ^ name4) & mask4) == 0 &&