Skip to content

Commit

Permalink
Fix unaligned load/store exception in luaR_findentry (#2702)
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryE authored Mar 24, 2019
1 parent a90de79 commit 3f5ae99
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/lua/lrotable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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 &&
Expand Down

0 comments on commit 3f5ae99

Please sign in to comment.