diff --git a/lib/dns/qp.c b/lib/dns/qp.c index ee78b98c30..f71f4dd925 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -2179,18 +2179,22 @@ dns_qp_lookup(dns_qpreadable_t qpr, const dns_name_t *name, * the predecessor name for a non-exact match. * * if 'matched' is true, then the search ended at a leaf. - * if it was not an exact match, then we're now pointing at - * the immediate successor of the searched-for name, and can - * use the qpiter stack we've constructed to step back to - * the predecessor. if it was an exact match, we don't need to - * do anything. + * if it was not an exact match, then we're now pointing + * at either the immediate predecessor or the immediate + * successor of the searched-for name; if successor, we can + * now use the qpiter stack we've constructed to step back to + * the predecessor. if we're pointed at the predecessor + * or it was an exact match, we don't need to do anything. * * if 'matched' is false, then the search failed at a branch * node, and we would already have positioned the iterator * at the predecessor. */ if (getpred && matched) { - if (offset != QPKEY_EQUAL) { + if (offset != QPKEY_EQUAL && + (offset <= searchlen && offset <= foundlen && + found[offset] > search[offset])) + { prevleaf(iter); } } diff --git a/tests/dns/qp_test.c b/tests/dns/qp_test.c index d68ac263c1..28ea2266b7 100644 --- a/tests/dns/qp_test.c +++ b/tests/dns/qp_test.c @@ -660,7 +660,7 @@ ISC_RUN_TEST_IMPL(predecessors) { { "a.b.c.e.f.", "a.b.c.d.e.", ISC_R_NOTFOUND }, { "z.y.x.", "a.b.c.d.e.", ISC_R_NOTFOUND }, { "w.c.d.", "x.k.c.d.", DNS_R_PARTIALMATCH }, - { "z.z.z.z.k.c.d.", "a.b.c.d.", DNS_R_PARTIALMATCH }, + { "z.z.z.z.k.c.d.", "x.k.c.d.", DNS_R_PARTIALMATCH }, { "w.k.c.d.", "a.b.c.d.", DNS_R_PARTIALMATCH }, { "d.a.", "e.d.c.b.a.", DNS_R_PARTIALMATCH }, { "0.b.c.d.e.", "x.k.c.d.", ISC_R_NOTFOUND }, @@ -686,7 +686,7 @@ ISC_RUN_TEST_IMPL(predecessors) { { "a.b.c.e.f.", "a.b.c.d.e.", DNS_R_PARTIALMATCH }, { "z.y.x.", "a.b.c.d.e.", DNS_R_PARTIALMATCH }, { "w.c.d.", "x.k.c.d.", DNS_R_PARTIALMATCH }, - { "z.z.z.z.k.c.d.", "a.b.c.d.", DNS_R_PARTIALMATCH }, + { "z.z.z.z.k.c.d.", "x.k.c.d.", DNS_R_PARTIALMATCH }, { "w.k.c.d.", "a.b.c.d.", DNS_R_PARTIALMATCH }, { "d.a.", "e.d.c.b.a.", DNS_R_PARTIALMATCH }, { "0.b.c.d.e.", "x.k.c.d.", DNS_R_PARTIALMATCH },