Blame SOURCES/bind99-CVE-2016-1285-CVE-2016-1286.patch

900526
diff --git a/bin/named/control.c b/bin/named/control.c
900526
index fabe442..06eadce 100644
900526
--- a/bin/named/control.c
900526
+++ b/bin/named/control.c
900526
@@ -69,7 +69,7 @@ ns_control_docommand(isccc_sexpr_t *message, isc_buffer_t *text) {
900526
 #endif
900526
 
900526
 	data = isccc_alist_lookup(message, "_data");
900526
-	if (data == NULL) {
900526
+	if (!isccc_alist_alistp(data)) {
900526
 		/*
900526
 		 * No data section.
900526
 		 */
900526
diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c
900526
index c46a6e1..ef32790 100644
900526
--- a/bin/named/controlconf.c
900526
+++ b/bin/named/controlconf.c
900526
@@ -396,7 +396,7 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) {
900526
 	 * Limit exposure to replay attacks.
900526
 	 */
900526
 	_ctrl = isccc_alist_lookup(request, "_ctrl");
900526
-	if (_ctrl == NULL) {
900526
+	if (!isccc_alist_alistp(_ctrl)) {
900526
 		log_invalid(&conn->ccmsg, ISC_R_FAILURE);
900526
 		goto cleanup_request;
900526
 	}
900526
diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c
900526
index ba2c3f6..9a007e2 100644
900526
--- a/bin/rndc/rndc.c
900526
+++ b/bin/rndc/rndc.c
900526
@@ -252,8 +252,8 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event) {
900526
 	DO("parse message", isccc_cc_fromwire(&source, &response, &secret));
900526
 
900526
 	data = isccc_alist_lookup(response, "_data");
900526
-	if (data == NULL)
900526
-		fatal("no data section in response");
900526
+	if (!isccc_alist_alistp(data))
900526
+		fatal("bad or missing data section in response");
900526
 	result = isccc_cc_lookupstring(data, "err", &errormsg);
900526
 	if (result == ISC_R_SUCCESS) {
900526
 		failed = ISC_TRUE;
900526
@@ -316,8 +316,8 @@ rndc_recvnonce(isc_task_t *task, isc_event_t *event) {
900526
 	DO("parse message", isccc_cc_fromwire(&source, &response, &secret));
900526
 
900526
 	_ctrl = isccc_alist_lookup(response, "_ctrl");
900526
-	if (_ctrl == NULL)
900526
-		fatal("_ctrl section missing");
900526
+	if (!isccc_alist_alistp(_ctrl))
900526
+		fatal("bad or missing ctrl section in response");
900526
 	nonce = 0;
900526
 	if (isccc_cc_lookupuint32(_ctrl, "_nonce", &nonce) != ISC_R_SUCCESS)
900526
 		nonce = 0;
900526
diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c
900526
index d220986..8696b15 100644
900526
--- a/lib/dns/resolver.c
900526
+++ b/lib/dns/resolver.c
900526
@@ -5408,14 +5408,11 @@ cname_target(dns_rdataset_t *rdataset, dns_name_t *tname) {
900526
 }
900526
 
900526
 static inline isc_result_t
900526
-dname_target(fetchctx_t *fctx, dns_rdataset_t *rdataset, dns_name_t *qname,
900526
-	     dns_name_t *oname, dns_fixedname_t *fixeddname)
900526
+dname_target(dns_rdataset_t *rdataset, dns_name_t *qname,
900526
+	     unsigned int nlabels, dns_fixedname_t *fixeddname)
900526
 {
900526
 	isc_result_t result;
900526
 	dns_rdata_t rdata = DNS_RDATA_INIT;
900526
-	unsigned int nlabels;
900526
-	int order;
900526
-	dns_namereln_t namereln;
900526
 	dns_rdata_dname_t dname;
900526
 	dns_fixedname_t prefix;
900526
 
900526
@@ -5430,21 +5427,6 @@ dname_target(fetchctx_t *fctx, dns_rdataset_t *rdataset, dns_name_t *qname,
900526
 	if (result != ISC_R_SUCCESS)
900526
 		return (result);
900526
 
900526
-	/*
900526
-	 * Get the prefix of qname.
900526
-	 */
900526
-	namereln = dns_name_fullcompare(qname, oname, &order, &nlabels);
900526
-	if (namereln != dns_namereln_subdomain) {
900526
-		char qbuf[DNS_NAME_FORMATSIZE];
900526
-		char obuf[DNS_NAME_FORMATSIZE];
900526
-
900526
-		dns_rdata_freestruct(&dname);
900526
-		dns_name_format(qname, qbuf, sizeof(qbuf));
900526
-		dns_name_format(oname, obuf, sizeof(obuf));
900526
-		log_formerr(fctx, "unrelated DNAME in answer: "
900526
-				   "%s is not in %s", qbuf, obuf);
900526
-		return (DNS_R_FORMERR);
900526
-	}
900526
 	dns_fixedname_init(&prefix);
900526
 	dns_name_split(qname, nlabels, dns_fixedname_name(&prefix), NULL);
900526
 	dns_fixedname_init(fixeddname);
900526
@@ -6057,13 +6039,13 @@ static isc_result_t
900526
 answer_response(fetchctx_t *fctx) {
900526
 	isc_result_t result;
900526
 	dns_message_t *message;
900526
-	dns_name_t *name, *qname, tname, *ns_name;
900526
+	dns_name_t *name, *dname = NULL, *qname, tname, *ns_name;
900526
 	dns_rdataset_t *rdataset, *ns_rdataset;
900526
 	isc_boolean_t done, external, chaining, aa, found, want_chaining;
900526
 	isc_boolean_t have_answer, found_cname, found_type, wanted_chaining;
900526
 	unsigned int aflag;
900526
 	dns_rdatatype_t type;
900526
-	dns_fixedname_t dname, fqname;
900526
+	dns_fixedname_t fdname, fqname;
900526
 	dns_view_t *view;
900526
 
900526
 	FCTXTRACE("answer_response");
900526
@@ -6091,10 +6073,15 @@ answer_response(fetchctx_t *fctx) {
900526
 	view = fctx->res->view;
900526
 	result = dns_message_firstname(message, DNS_SECTION_ANSWER);
900526
 	while (!done && result == ISC_R_SUCCESS) {
900526
+		dns_namereln_t namereln;
900526
+		int order;
900526
+		unsigned int nlabels;
900526
+
900526
 		name = NULL;
900526
 		dns_message_currentname(message, DNS_SECTION_ANSWER, &name);
900526
 		external = ISC_TF(!dns_name_issubdomain(name, &fctx->domain));
900526
-		if (dns_name_equal(name, qname)) {
900526
+		namereln = dns_name_fullcompare(qname, name, &order, &nlabels);
900526
+		if (namereln == dns_namereln_equal) {
900526
 			wanted_chaining = ISC_FALSE;
900526
 			for (rdataset = ISC_LIST_HEAD(name->list);
900526
 			     rdataset != NULL;
900526
@@ -6219,10 +6206,11 @@ answer_response(fetchctx_t *fctx) {
900526
 						 */
900526
 						INSIST(!external);
900526
 						if (aflag ==
900526
-						    DNS_RDATASETATTR_ANSWER)
900526
+						    DNS_RDATASETATTR_ANSWER) {
900526
 							have_answer = ISC_TRUE;
900526
-						name->attributes |=
900526
-							DNS_NAMEATTR_ANSWER;
900526
+							name->attributes |=
900526
+								DNS_NAMEATTR_ANSWER;
900526
+						}
900526
 						rdataset->attributes |= aflag;
900526
 						if (aa)
900526
 							rdataset->trust =
900526
@@ -6277,6 +6265,8 @@ answer_response(fetchctx_t *fctx) {
900526
 			if (wanted_chaining)
900526
 				chaining = ISC_TRUE;
900526
 		} else {
900526
+			dns_rdataset_t *dnameset = NULL;
900526
+
900526
 			/*
900526
 			 * Look for a DNAME (or its SIG).  Anything else is
900526
 			 * ignored.
900526
@@ -6284,32 +6274,56 @@ answer_response(fetchctx_t *fctx) {
900526
 			wanted_chaining = ISC_FALSE;
900526
 			for (rdataset = ISC_LIST_HEAD(name->list);
900526
 			     rdataset != NULL;
900526
-			     rdataset = ISC_LIST_NEXT(rdataset, link)) {
900526
-				isc_boolean_t found_dname = ISC_FALSE;
900526
-				dns_name_t *dname_name;
900526
+			     rdataset = ISC_LIST_NEXT(rdataset, link))
900526
+			{
900526
+				/*
900526
+				 * Only pass DNAME or RRSIG(DNAME).
900526
+				 */
900526
+				if (rdataset->type != dns_rdatatype_dname &&
900526
+				    (rdataset->type != dns_rdatatype_rrsig ||
900526
+				     rdataset->covers != dns_rdatatype_dname))
900526
+					continue;
900526
+
900526
+				/*
900526
+				 * If we're not chaining, then the DNAME and
900526
+				 * its signature should not be external.
900526
+				 */
900526
+				if (!chaining && external) {
900526
+					char qbuf[DNS_NAME_FORMATSIZE];
900526
+					char obuf[DNS_NAME_FORMATSIZE];
900526
+
900526
+					dns_name_format(name, qbuf,
900526
+							sizeof(qbuf));
900526
+					dns_name_format(&fctx->domain, obuf,
900526
+							sizeof(obuf));
900526
+					log_formerr(fctx, "external DNAME or "
900526
+						    "RRSIG covering DNAME "
900526
+						    "in answer: %s is "
900526
+						    "not in %s", qbuf, obuf);
900526
+					return (DNS_R_FORMERR);
900526
+				}
900526
+
900526
+				if (namereln != dns_namereln_subdomain) {
900526
+					char qbuf[DNS_NAME_FORMATSIZE];
900526
+					char obuf[DNS_NAME_FORMATSIZE];
900526
+
900526
+					dns_name_format(qname, qbuf,
900526
+							sizeof(qbuf));
900526
+					dns_name_format(name, obuf,
900526
+							sizeof(obuf));
900526
+					log_formerr(fctx, "unrelated DNAME "
900526
+						    "in answer: %s is "
900526
+						    "not in %s", qbuf, obuf);
900526
+					return (DNS_R_FORMERR);
900526
+				}
900526
 
900526
-				found = ISC_FALSE;
900526
 				aflag = 0;
900526
 				if (rdataset->type == dns_rdatatype_dname) {
900526
-					/*
900526
-					 * We're looking for something else,
900526
-					 * but we found a DNAME.
900526
-					 *
900526
-					 * If we're not chaining, then the
900526
-					 * DNAME should not be external.
900526
-					 */
900526
-					if (!chaining && external) {
900526
-						log_formerr(fctx,
900526
-							    "external DNAME");
900526
-						return (DNS_R_FORMERR);
900526
-					}
900526
-					found = ISC_TRUE;
900526
 					want_chaining = ISC_TRUE;
900526
 					POST(want_chaining);
900526
 					aflag = DNS_RDATASETATTR_ANSWER;
900526
-					result = dname_target(fctx, rdataset,
900526
-							      qname, name,
900526
-							      &dname);
900526
+					result = dname_target(rdataset, qname,
900526
+							      nlabels, &fdname);
900526
 					if (result == ISC_R_NOSPACE) {
900526
 						/*
900526
 						 * We can't construct the
900526
@@ -6321,90 +6335,73 @@ answer_response(fetchctx_t *fctx) {
900526
 					} else if (result != ISC_R_SUCCESS)
900526
 						return (result);
900526
 					else
900526
-						found_dname = ISC_TRUE;
900526
+						dnameset = rdataset;
900526
 
900526
-					dname_name = dns_fixedname_name(&dname);
900526
+					dname = dns_fixedname_name(&fdname);
900526
 					if (!is_answertarget_allowed(view,
900526
-							qname,
900526
-							rdataset->type,
900526
-							dname_name,
900526
-							&fctx->domain)) {
900526
+							qname, rdataset->type,
900526
+							dname, &fctx->domain)) {
900526
 						return (DNS_R_SERVFAIL);
900526
 					}
900526
-				} else if (rdataset->type == dns_rdatatype_rrsig
900526
-					   && rdataset->covers ==
900526
-					   dns_rdatatype_dname) {
900526
+				} else {
900526
 					/*
900526
 					 * We've found a signature that
900526
 					 * covers the DNAME.
900526
 					 */
900526
-					found = ISC_TRUE;
900526
 					aflag = DNS_RDATASETATTR_ANSWERSIG;
900526
 				}
900526
 
900526
-				if (found) {
900526
+				/*
900526
+				 * We've found an answer to our
900526
+				 * question.
900526
+				 */
900526
+				name->attributes |= DNS_NAMEATTR_CACHE;
900526
+				rdataset->attributes |= DNS_RDATASETATTR_CACHE;
900526
+				rdataset->trust = dns_trust_answer;
900526
+				if (!chaining) {
900526
 					/*
900526
-					 * We've found an answer to our
900526
-					 * question.
900526
+					 * This data is "the" answer to
900526
+					 * our question only if we're
900526
+					 * not chaining.
900526
 					 */
900526
-					name->attributes |=
900526
-						DNS_NAMEATTR_CACHE;
900526
-					rdataset->attributes |=
900526
-						DNS_RDATASETATTR_CACHE;
900526
-					rdataset->trust = dns_trust_answer;
900526
-					if (!chaining) {
900526
-						/*
900526
-						 * This data is "the" answer
900526
-						 * to our question only if
900526
-						 * we're not chaining.
900526
-						 */
900526
-						INSIST(!external);
900526
-						if (aflag ==
900526
-						    DNS_RDATASETATTR_ANSWER)
900526
-							have_answer = ISC_TRUE;
900526
+					INSIST(!external);
900526
+					if (aflag == DNS_RDATASETATTR_ANSWER) {
900526
+						have_answer = ISC_TRUE;
900526
 						name->attributes |=
900526
 							DNS_NAMEATTR_ANSWER;
900526
-						rdataset->attributes |= aflag;
900526
-						if (aa)
900526
-							rdataset->trust =
900526
-							  dns_trust_authanswer;
900526
-					} else if (external) {
900526
-						rdataset->attributes |=
900526
-						    DNS_RDATASETATTR_EXTERNAL;
900526
-					}
900526
-
900526
-					/*
900526
-					 * DNAME chaining.
900526
-					 */
900526
-					if (found_dname) {
900526
-						/*
900526
-						 * Copy the dname into the
900526
-						 * qname fixed name.
900526
-						 *
900526
-						 * Although we check for
900526
-						 * failure of the copy
900526
-						 * operation, in practice it
900526
-						 * should never fail since
900526
-						 * we already know that the
900526
-						 * result fits in a fixedname.
900526
-						 */
900526
-						dns_fixedname_init(&fqname);
900526
-						result = dns_name_copy(
900526
-						  dns_fixedname_name(&dname),
900526
-						  dns_fixedname_name(&fqname),
900526
-						  NULL);
900526
-						if (result != ISC_R_SUCCESS)
900526
-							return (result);
900526
-						wanted_chaining = ISC_TRUE;
900526
-						name->attributes |=
900526
-							DNS_NAMEATTR_CHAINING;
900526
-						rdataset->attributes |=
900526
-						    DNS_RDATASETATTR_CHAINING;
900526
-						qname = dns_fixedname_name(
900526
-								   &fqname);
900526
 					}
900526
+					rdataset->attributes |= aflag;
900526
+					if (aa)
900526
+						rdataset->trust =
900526
+						  dns_trust_authanswer;
900526
+				} else if (external) {
900526
+					rdataset->attributes |=
900526
+					    DNS_RDATASETATTR_EXTERNAL;
900526
 				}
900526
 			}
900526
+
900526
+			/*
900526
+			 * DNAME chaining.
900526
+			 */
900526
+			if (dnameset != NULL) {
900526
+				/*
900526
+				 * Copy the dname into the qname fixed name.
900526
+				 *
900526
+				 * Although we check for failure of the copy
900526
+				 * operation, in practice it should never fail
900526
+				 * since we already know that the  result fits
900526
+				 * in a fixedname.
900526
+				 */
900526
+				dns_fixedname_init(&fqname);
900526
+				qname = dns_fixedname_name(&fqname);
900526
+				result = dns_name_copy(dname, qname, NULL);
900526
+				if (result != ISC_R_SUCCESS)
900526
+					return (result);
900526
+				wanted_chaining = ISC_TRUE;
900526
+				name->attributes |= DNS_NAMEATTR_CHAINING;
900526
+				dnameset->attributes |=
900526
+					    DNS_RDATASETATTR_CHAINING;
900526
+			}
900526
 			if (wanted_chaining)
900526
 				chaining = ISC_TRUE;
900526
 		}
900526
diff --git a/lib/isccc/cc.c b/lib/isccc/cc.c
900526
index ae5391a..10e5dc9 100644
900526
--- a/lib/isccc/cc.c
900526
+++ b/lib/isccc/cc.c
900526
@@ -286,10 +286,10 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length,
900526
 	 * Extract digest.
900526
 	 */
900526
 	_auth = isccc_alist_lookup(alist, "_auth");
900526
-	if (_auth == NULL)
900526
+	if (!isccc_alist_alistp(_auth))
900526
 		return (ISC_R_FAILURE);
900526
 	hmd5 = isccc_alist_lookup(_auth, "hmd5");
900526
-	if (hmd5 == NULL)
900526
+	if (!isccc_sexpr_binaryp(hmd5))
900526
 		return (ISC_R_FAILURE);
900526
 	/*
900526
 	 * Compute digest.
900526
@@ -543,7 +543,7 @@ isccc_cc_createack(isccc_sexpr_t *message, isc_boolean_t ok,
900526
 	REQUIRE(ackp != NULL && *ackp == NULL);
900526
 
900526
 	_ctrl = isccc_alist_lookup(message, "_ctrl");
900526
-	if (_ctrl == NULL ||
900526
+	if (!isccc_alist_alistp(_ctrl) ||
900526
 	    isccc_cc_lookupuint32(_ctrl, "_ser", &serial) != ISC_R_SUCCESS ||
900526
 	    isccc_cc_lookupuint32(_ctrl, "_tim", &t) != ISC_R_SUCCESS)
900526
 		return (ISC_R_FAILURE);
900526
@@ -588,7 +588,7 @@ isccc_cc_isack(isccc_sexpr_t *message)
900526
 	isccc_sexpr_t *_ctrl;
900526
 
900526
 	_ctrl = isccc_alist_lookup(message, "_ctrl");
900526
-	if (_ctrl == NULL)
900526
+	if (!isccc_alist_alistp(_ctrl))
900526
 		return (ISC_FALSE);
900526
 	if (isccc_cc_lookupstring(_ctrl, "_ack", NULL) == ISC_R_SUCCESS)
900526
 		return (ISC_TRUE);
900526
@@ -601,7 +601,7 @@ isccc_cc_isreply(isccc_sexpr_t *message)
900526
 	isccc_sexpr_t *_ctrl;
900526
 
900526
 	_ctrl = isccc_alist_lookup(message, "_ctrl");
900526
-	if (_ctrl == NULL)
900526
+	if (!isccc_alist_alistp(_ctrl))
900526
 		return (ISC_FALSE);
900526
 	if (isccc_cc_lookupstring(_ctrl, "_rpl", NULL) == ISC_R_SUCCESS)
900526
 		return (ISC_TRUE);
900526
@@ -621,7 +621,7 @@ isccc_cc_createresponse(isccc_sexpr_t *message, isccc_time_t now,
900526
 
900526
 	_ctrl = isccc_alist_lookup(message, "_ctrl");
900526
 	_data = isccc_alist_lookup(message, "_data");
900526
-	if (_ctrl == NULL || _data == NULL ||
900526
+	if (!isccc_alist_alistp(_ctrl) || !isccc_alist_alistp(_data) ||
900526
 	    isccc_cc_lookupuint32(_ctrl, "_ser", &serial) != ISC_R_SUCCESS ||
900526
 	    isccc_cc_lookupstring(_data, "type", &type) != ISC_R_SUCCESS)
900526
 		return (ISC_R_FAILURE);
900526
@@ -810,7 +810,7 @@ isccc_cc_checkdup(isccc_symtab_t *symtab, isccc_sexpr_t *message,
900526
 	isccc_sexpr_t *_ctrl;
900526
 
900526
 	_ctrl = isccc_alist_lookup(message, "_ctrl");
900526
-	if (_ctrl == NULL ||
900526
+	if (!isccc_alist_alistp(_ctrl) ||
900526
 	    isccc_cc_lookupstring(_ctrl, "_ser", &_ser) != ISC_R_SUCCESS ||
900526
 	    isccc_cc_lookupstring(_ctrl, "_tim", &_tim) != ISC_R_SUCCESS)
900526
 		return (ISC_R_FAILURE);