$NetBSD: patch-am,v 1.1 2008/03/19 22:55:21 tonnerre Exp $

--- server/MaraDNS.c.orig	2007-05-17 06:01:44.000000000 +0200
+++ server/MaraDNS.c
@@ -636,7 +636,8 @@ int udpsuccess(rr *where, int id, int so
                is buggy if we round-robin rotate data when we allow more than
                one additional record to be create per answer/authoritative
                record.  */
-            if(rotate_2nd != 0 && max_ar_chain == 1 && rotate_last != 0) {
+            if(rotate_2nd != 0 && max_ar_chain == 1 && rotate_last != 0
+		&& first_rr_type != RR_NS) {
                 /* If it makes sense to do a round-robin rotation, do so.
 		 * Make rotate_1st, which was the first record, the last
 		 * record; make rotate_2nd, which was the second record,
@@ -900,7 +901,8 @@ int udpsuccess(rr *where, int id, int so
         rotate_last = where;
         where = where->next;
         /* If it makes sense to do a round-robin rotation, do so */
-        if(where == 0 && rotate_2nd != 0 && max_ar_chain == 1) {
+        if(where == 0 && rotate_2nd != 0 && max_ar_chain == 1
+	    && first_rr_type != RR_NS) {
             /* For records in the cache, we need to make sure that
                the custodian properly points to the first record
                in the chain or we will leak memory */
@@ -1113,7 +1115,8 @@ int add_answer(rr *where,js_string *most
                is buggy if we round-robin rotate data when we allow more than
                one additional record to be create per answer/authoritative
                record.  */
-            if(rotate_2nd != 0 && max_ar_chain == 1 && rotate_done == 0) {
+            if(rotate_2nd != 0 && max_ar_chain == 1 && rotate_done == 0
+		&& first_rr_type != RR_NS) {
                 rotate_done = 1;
                 /* If it makes sense to do a round-robin rotation */
                 rotate_1st->next = where;
