Skip to content

Commit 00aae12

Browse files
committed
ITS#8321 fix ambiguity in cursor_put fixup
After delete/add of a node, other nodes may no longer be pointing at the data they intended. This can confuse subsequent fixups.
1 parent e0316e0 commit 00aae12

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libraries/liblmdb/mdb.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6683,22 +6683,28 @@ mdb_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
66836683
} else {
66846684
/* There is room already in this leaf page. */
66856685
rc = mdb_node_add(mc, mc->mc_ki[mc->mc_top], key, rdata, 0, nflags);
6686-
if (rc == 0 && insert_key) {
6686+
if (rc == 0) {
66876687
/* Adjust other cursors pointing to mp */
66886688
MDB_cursor *m2, *m3;
66896689
MDB_dbi dbi = mc->mc_dbi;
66906690
unsigned i = mc->mc_top;
66916691
MDB_page *mp = mc->mc_pg[i];
6692+
int nkeys = NUMKEYS(mp);
66926693

66936694
for (m2 = mc->mc_txn->mt_cursors[dbi]; m2; m2=m2->mc_next) {
66946695
if (mc->mc_flags & C_SUB)
66956696
m3 = &m2->mc_xcursor->mx_cursor;
66966697
else
66976698
m3 = m2;
6698-
if (m3 == mc || m3->mc_snum < mc->mc_snum) continue;
6699-
if (m3->mc_pg[i] == mp && m3->mc_ki[i] >= mc->mc_ki[i]) {
6699+
if (m3 == mc || m3->mc_snum < mc->mc_snum || m3->mc_pg[i] != mp) continue;
6700+
if (m3->mc_ki[i] >= mc->mc_ki[i] && insert_key) {
67006701
m3->mc_ki[i]++;
67016702
}
6703+
if (m3->mc_xcursor && (m3->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED)) {
6704+
MDB_node *n2 = NODEPTR(mp, m3->mc_ki[i]);
6705+
if ((n2->mn_flags & (F_SUBDATA|F_DUPDATA)) == F_DUPDATA)
6706+
m3->mc_xcursor->mx_cursor.mc_pg[0] = NODEDATA(n2);
6707+
}
67026708
}
67036709
}
67046710
}

0 commit comments

Comments
 (0)