From: Matthijs Mekking Date: Wed, 15 May 2024 08:59:07 +0000 (+0200) Subject: Get anyleaf when qp lookup is on a dead end branch X-Git-Tag: v9.20.0~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b8c16d7a47a19fe91674566fe46ced5f5574219;p=thirdparty%2Fbind9.git 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. --- diff --git a/lib/dns/qp.c b/lib/dns/qp.c index 3b73f4755b8..dbe28b66890 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -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);