2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

fix: dev: step() could ignore rollbacks

The `step()` function (used for stepping to the prececessor or successor of a database node) could overlook a node if there was an rdataset that was marked IGNORE because it had been rolled back, covering an active rdataset under it.

Closes #5170

Merge branch '5170-step-ignores-rollback' into 'main'

See merge request isc-projects/bind9!10103
This commit is contained in:
Evan Hunt 2025-03-14 23:19:36 +00:00
commit 3b0b658a52
3 changed files with 198 additions and 5 deletions

View File

@ -2696,13 +2696,25 @@ step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction,
while (result == ISC_R_SUCCESS) {
isc_rwlock_t *nlock = &qpdb->buckets[node->locknum].lock;
isc_rwlocktype_t nlocktype = isc_rwlocktype_none;
dns_slabheader_t *header_next = NULL;
NODE_RDLOCK(nlock, &nlocktype);
for (header = node->data; header != NULL; header = header->next)
for (header = node->data; header != NULL; header = header_next)
{
if (header->serial <= search->serial &&
!IGNORE(header) && !NONEXISTENT(header))
{
header_next = header->next;
while (header != NULL) {
if (header->serial <= search->serial &&
!IGNORE(header))
{
if (NONEXISTENT(header)) {
header = NULL;
}
break;
} else {
header = header->down;
}
}
if (header != NULL) {
break;
}
}

View File

@ -351,8 +351,40 @@ ISC_LOOP_TEST_IMPL(version) {
result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node,
foundname, &rdataset, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
dns_rdataset_disassociate(&rdataset);
dns_db_detachnode(db, &node);
/* Now we create a node with an empty parent */
result = dns_db_newversion(db, &new);
dns_test_namefromstring("long.ent.name.test.test.", &fname);
result = dns_db_findnode(db, name, true, &node);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_db_addrdataset(db, node, new, 0, &rdataset, 0, NULL);
assert_int_equal(result, ISC_R_SUCCESS);
dns_rdataset_disassociate(&rdataset);
dns_rdataset_init(&rdataset);
/* look up the ENT; it should be empty */
dns_test_namefromstring("ent.name.test.test.", &fname);
dns_db_detachnode(db, &node);
result = dns_db_find(db, name, new, dns_rdatatype_a, 0, 0, &node,
foundname, &rdataset, NULL);
assert_int_equal(result, DNS_R_EMPTYNAME);
/* ... but then we roll it back... */
dns_db_closeversion(db, &new, false);
/* ... and the ENT should be NXDOMAIN now */
dns_test_namefromstring("ent.name.test.test.", &fname);
result = dns_db_find(db, name, ver, dns_rdatatype_a, 0, 0, &node,
foundname, &rdataset, NULL);
assert_int_equal(result, DNS_R_NXDOMAIN);
if (dns_rdataset_isassociated(&rdataset)) {
dns_rdataset_disassociate(&rdataset);
}
if (node != NULL) {
dns_db_detachnode(db, &node);
}
dns_db_closeversion(db, &ver, false);
dns_db_detach(&db);

View File

@ -363,6 +363,154 @@ ISC_RUN_TEST_IMPL(getnsec3parameters) {
db1, v2, &hash, &flags, &iterations, salt, &salt_length));
}
/*
* Check that the correct node contents are found after a rollback.
*/
ISC_RUN_TEST_IMPL(rollback) {
isc_result_t res;
dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT;
dns_rdataset_t input1 = DNS_RDATASET_INIT;
dns_rdataset_t input2 = DNS_RDATASET_INIT;
dns_rdataset_t rdataset1 = DNS_RDATASET_INIT;
dns_rdataset_t rdataset2 = DNS_RDATASET_INIT;
dns_rdatalist_t rdatalist1, rdatalist2;
dns_rdata_t out1 = DNS_RDATA_INIT, out2 = DNS_RDATA_INIT;
dns_dbnode_t *node = NULL;
char *txt1 = (char *)"\006text 1";
char *txt2 = (char *)"\006text 2";
size_t len1 = strlen(txt1), len2 = strlen(txt2);
char buf[1024];
isc_buffer_t b;
UNUSED(state);
isc_buffer_init(&b, buf, sizeof(buf));
/* Set up two rdatasets to insert */
rdata1.rdclass = dns_rdataclass_in;
rdata1.type = dns_rdatatype_txt;
rdata2 = rdata1;
rdata1.length = len1;
rdata1.data = (unsigned char *)txt1;
rdata2.length = len2;
rdata2.data = (unsigned char *)txt2;
dns_rdatalist_init(&rdatalist1);
rdatalist1.rdclass = dns_rdataclass_in;
rdatalist1.type = dns_rdatatype_txt;
rdatalist1.ttl = 3600;
rdatalist2 = rdatalist1;
ISC_LIST_APPEND(rdatalist1.rdata, &rdata1, link);
ISC_LIST_APPEND(rdatalist2.rdata, &rdata2, link);
dns_rdatalist_tordataset(&rdatalist1, &input1);
dns_rdatalist_tordataset(&rdatalist2, &input2);
/* db1: Insert the first version ("text 1"), and commit */
res = dns_db_findnode(db1, dns_rootname, true, &node);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_addrdataset(db1, node, v1, 0, &input1, 0, NULL);
assert_int_equal(res, ISC_R_SUCCESS);
dns_db_closeversion(db1, &v1, true); /* commit */
assert_null(v1);
dns_db_detachnode(db1, &node);
assert_null(node);
/* db2: Insert the first version ("text 1"), and commit */
res = dns_db_findnode(db2, dns_rootname, true, &node);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_addrdataset(db2, node, v2, 0, &input1, 0, NULL);
assert_int_equal(res, ISC_R_SUCCESS);
dns_db_closeversion(db2, &v2, true); /* commit */
assert_null(v2);
dns_db_detachnode(db2, &node);
assert_null(node);
/* Reopen the versions */
dns_db_newversion(db1, &v1);
assert_non_null(v1);
dns_db_newversion(db2, &v2);
assert_non_null(v2);
/* db1: Insert the second version ("text 2"), and roll back */
res = dns_db_findnode(db1, dns_rootname, true, &node);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_addrdataset(db1, node, v1, 0, &input2, 0, NULL);
assert_int_equal(res, ISC_R_SUCCESS);
dns_db_closeversion(db1, &v1, false); /* rollback */
assert_null(v1);
dns_db_detachnode(db1, &node);
assert_null(node);
/* db2: Insert the second version ("text 2"), and commit */
res = dns_db_findnode(db2, dns_rootname, true, &node);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_addrdataset(db2, node, v2, 0, &input2, 0, NULL);
assert_int_equal(res, ISC_R_SUCCESS);
dns_db_closeversion(db2, &v2, true); /* commit */
assert_null(v2);
dns_db_detachnode(db2, &node);
assert_null(node);
/* db1: Look it up and check that the first version is found */
dns_db_currentversion(db1, &v1);
assert_non_null(v1);
res = dns_db_findnode(db1, dns_rootname, true, &node);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_findrdataset(db1, node, v1, dns_rdatatype_txt, 0, 0,
&rdataset1, NULL);
assert_int_equal(res, ISC_R_SUCCESS);
/* db1: Convert result to text */
res = dns_rdataset_first(&rdataset1);
assert_int_equal(res, ISC_R_SUCCESS);
dns_rdataset_current(&rdataset1, &out1);
res = dns_rdata_totext(&out1, NULL, &b);
assert_int_equal(res, ISC_R_SUCCESS);
isc_buffer_putuint8(&b, 0);
/* db1: We should have "text 1" */
assert_string_equal(buf, "\"text 1\"");
dns_rdataset_disassociate(&rdataset1);
dns_db_closeversion(db1, &v1, true);
assert_null(v1);
dns_db_detachnode(db1, &node);
assert_null(node);
/* db2: Look it up and check that the second version is found */
dns_db_currentversion(db2, &v2);
assert_non_null(v2);
res = dns_db_findnode(db2, dns_rootname, true, &node);
assert_int_equal(res, ISC_R_SUCCESS);
res = dns_db_findrdataset(db2, node, v2, dns_rdatatype_txt, 0, 0,
&rdataset2, NULL);
assert_int_equal(res, ISC_R_SUCCESS);
/* db2: Convert result to text */
res = dns_rdataset_first(&rdataset2);
assert_int_equal(res, ISC_R_SUCCESS);
dns_rdataset_current(&rdataset2, &out2);
isc_buffer_init(&b, buf, sizeof(buf));
res = dns_rdata_totext(&out2, NULL, &b);
assert_int_equal(res, ISC_R_SUCCESS);
isc_buffer_putuint8(&b, 0);
/* db2: We should have "text 2" */
assert_string_equal(buf, "\"text 2\"");
dns_rdataset_disassociate(&rdataset2);
dns_db_closeversion(db2, &v2, true);
assert_null(v2);
dns_db_detachnode(db2, &node);
assert_null(node);
}
ISC_TEST_LIST_START
ISC_TEST_ENTRY_CUSTOM(find, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(allrdatasets, setup_test, teardown_test)
@ -373,6 +521,7 @@ ISC_TEST_ENTRY_CUSTOM(addrdataset, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(getnsec3parameters, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(attachversion, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(closeversion, setup_test, teardown_test)
ISC_TEST_ENTRY_CUSTOM(rollback, setup_test, teardown_test)
ISC_TEST_LIST_END
ISC_TEST_MAIN