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