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