900526
diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c
900526
index 9ad5f81..ffdde5e 100644
900526
--- a/lib/dns/resolver.c
900526
+++ b/lib/dns/resolver.c
900526
@@ -6229,15 +6229,19 @@ answer_response(fetchctx_t *fctx) {
900526
 						 * a CNAME or DNAME).
900526
 						 */
900526
 						INSIST(!external);
900526
-						if ((rdataset->type !=
900526
-						     dns_rdatatype_cname) ||
900526
-						    !found_dname ||
900526
-						    (aflag ==
900526
-						     DNS_RDATASETATTR_ANSWER))
900526
+						/*
900526
+						 * Don't use found_cname here
900526
+						 * as we have just set it
900526
+						 * above.
900526
+						 */
900526
+						if (cname == NULL &&
900526
+						    !found_dname &&
900526
+						    aflag ==
900526
+						     DNS_RDATASETATTR_ANSWER)
900526
 						{
900526
 							have_answer = ISC_TRUE;
900526
-							if (rdataset->type ==
900526
-							    dns_rdatatype_cname)
900526
+							if (found_cname &&
900526
+							    cname == NULL)
900526
 								cname = name;
900526
 							name->attributes |=
900526
 								DNS_NAMEATTR_ANSWER;