aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Pall <mike>2018-02-27 23:02:23 +0100
committerMike Pall <mike>2018-02-27 23:02:23 +0100
commit046129dbdda5261c1b17469a2895a113d14c070a (patch)
tree673301374959c5ce16b7ebb8ab44b135c8187094 /src
parent03cd5aa749c1bc3bb4b7d4289236b6096cb3dc85 (diff)
downloadluajit-046129dbdda5261c1b17469a2895a113d14c070a.tar.gz
luajit-046129dbdda5261c1b17469a2895a113d14c070a.tar.bz2
luajit-046129dbdda5261c1b17469a2895a113d14c070a.zip
Fix rechaining of pseudo-resurrected string keys.
This is a serious bug. But extremely hard to reproduce, so it went undetected for 8 years. One needs two resurrections with different main nodes, which are both in a hash chain which gets relinked on key insertion where the colliding node is in a non-main position. Phew. Thanks to lbeiming.
Diffstat (limited to 'src')
-rw-r--r--src/lj_tab.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lj_tab.c b/src/lj_tab.c
index 50f447e8..f2f3c0b0 100644
--- a/src/lj_tab.c
+++ b/src/lj_tab.c
@@ -457,6 +457,29 @@ TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key)
457 freenode->next = nn->next; 457 freenode->next = nn->next;
458 nn->next = n->next; 458 nn->next = n->next;
459 setmref(n->next, nn); 459 setmref(n->next, nn);
460 /*
461 ** Rechaining a resurrected string key creates a new dilemma:
462 ** Another string key may have originally been resurrected via
463 ** _any_ of the previous nodes as a chain anchor. Including
464 ** a node that had to be moved, which makes them unreachable.
465 ** It's not feasible to check for all previous nodes, so rechain
466 ** any string key that's currently in a non-main positions.
467 */
468 while ((nn = nextnode(freenode))) {
469 if (tvisstr(&nn->key) && !tvisnil(&nn->val)) {
470 Node *mn = hashstr(t, strV(&nn->key));
471 if (mn != freenode) {
472 freenode->next = nn->next;
473 nn->next = mn->next;
474 setmref(mn->next, nn);
475 } else {
476 freenode = nn;
477 }
478 } else {
479 freenode = nn;
480 }
481 }
482 break;
460 } else { 483 } else {
461 freenode = nn; 484 freenode = nn;
462 } 485 }