]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Get anyleaf when qp lookup is on a dead end branch
authorMatthijs Mekking <matthijs@isc.org>
Wed, 15 May 2024 08:59:07 +0000 (10:59 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Thu, 16 May 2024 09:49:41 +0000 (09:49 +0000)
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.

lib/dns/qp.c

index 3b73f4755b8a9e80056e1b6ca06792ca5ce9b140..dbe28b668908a3a5c49b3aedde1f33c75c7756f8 100644 (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);