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