Get anyleaf when qp lookup is on a dead end branch

Move the fix_iterator out of the loop and only call it when we found
a leaf node. This leaf node may be the wrong leaf node, but fix_iterator
should correct that.

Also, when we don't need to set the iterator, just get any leaf. We
only need to have a leaf for the qpkey_compare and the end result does
not matter if compare was against an ancestor leaf or any leaf below
that point.
This commit is contained in:
Matthijs Mekking
2024-05-15 10:59:07 +02:00
parent 6b89d66ce8
commit 8b8c16d7a4

View File

@@ -2337,38 +2337,22 @@ dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name,
* the loop.
*/
n = branch_twig_ptr(qp, n, bit);
iter->stack[++iter->sp] = n;
} else if (setiter) {
/*
* this branch is a dead end. however, the caller
* passed us an iterator, so we'll need to look
* for the predecessor of the searched-for-name;
* that will break the loop.
*/
fix_iterator(qp, iter, search, searchlen, bit, offset);
n = iter->stack[iter->sp];
} else {
/*
* this branch is a dead end, and the predecessor
* doesn't matter. now we just need to find a leaf
* to end on so that qpkey_leaf() will work below.
*/
if (chain->len > 0) {
/* we saved an ancestor leaf: use that */
n = chain->chain[chain->len - 1].node;
} else {
/* walk down to find the leftmost leaf */
n = anyleaf(qp, twigs);
}
iter->stack[++iter->sp] = n;
n = anyleaf(qp, twigs);
}
iter->stack[++iter->sp] = n;
}
if (matched && setiter) {
if (setiter) {
/*
* we found a leaf on a matching twig, but it
* might not be the leaf we wanted. if it isn't,
* and if the caller passed us an iterator,
* we found a leaf, but it might not be the leaf we wanted.
* if it isn't, and if the caller passed us an iterator,
* then we might need to reposition it.
*/
fix_iterator(qp, iter, search, searchlen, bit, offset);