900526
diff -pruN bind-9.9.4-P1/bin/named/query.c bind-9.9.4-P2/bin/named/query.c
900526
--- bind-9.9.4-P1/bin/named/query.c	2013-10-16 01:04:32.000000000 +0200
900526
+++ bind-9.9.4-P2/bin/named/query.c	2013-12-20 01:28:28.000000000 +0100
900526
@@ -5260,8 +5260,7 @@ query_findclosestnsec3(dns_name_t *qname
900526
 	dns_fixedname_t fixed;
900526
 	dns_hash_t hash;
900526
 	dns_name_t name;
900526
-	int order;
900526
-	unsigned int count;
900526
+	unsigned int skip = 0, labels;
900526
 	dns_rdata_nsec3_t nsec3;
900526
 	dns_rdata_t rdata = DNS_RDATA_INIT;
900526
 	isc_boolean_t optout;
900526
@@ -5276,6 +5275,7 @@ query_findclosestnsec3(dns_name_t *qname
900526
 
900526
 	dns_name_init(&name, NULL);
900526
 	dns_name_clone(qname, &name);
900526
+	labels = dns_name_countlabels(&name);
900526
 	dns_clientinfomethods_init(&cm, ns_client_sourceip);
900526
 	dns_clientinfo_init(&ci, client);
900526
 
900526
@@ -5309,13 +5309,14 @@ query_findclosestnsec3(dns_name_t *qname
900526
 		dns_rdata_reset(&rdata);
900526
 		optout = ISC_TF((nsec3.flags & DNS_NSEC3FLAG_OPTOUT) != 0);
900526
 		if (found != NULL && optout &&
900526
-		    dns_name_fullcompare(&name, dns_db_origin(db), &order,
900526
-					 &count) == dns_namereln_subdomain) {
900526
+		    dns_name_issubdomain(&name, dns_db_origin(db)))
900526
+		{
900526
 			dns_rdataset_disassociate(rdataset);
900526
 			if (dns_rdataset_isassociated(sigrdataset))
900526
 				dns_rdataset_disassociate(sigrdataset);
900526
-			count = dns_name_countlabels(&name) - 1;
900526
-			dns_name_getlabelsequence(&name, 1, count, &name);
900526
+			skip++;
900526
+			dns_name_getlabelsequence(qname, skip, labels - skip,
900526
+						  &name);
900526
 			ns_client_log(client, DNS_LOGCATEGORY_DNSSEC,
900526
 				      NS_LOGMODULE_QUERY, ISC_LOG_DEBUG(3),
900526
 				      "looking for closest provable encloser");
900526
@@ -5333,7 +5334,11 @@ query_findclosestnsec3(dns_name_t *qname
900526
 		ns_client_log(client, DNS_LOGCATEGORY_DNSSEC,
900526
 			      NS_LOGMODULE_QUERY, ISC_LOG_WARNING,
900526
 			      "expected covering NSEC3, got an exact match");
900526
-	if (found != NULL)
900526
+	if (found == qname) {
900526
+		if (skip != 0U)
900526
+			dns_name_getlabelsequence(qname, skip, labels - skip,
900526
+						  found);
900526
+	} else if (found != NULL)
900526
 		dns_name_copy(&name, found, NULL);
900526
 	return;
900526
 }