Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Mar 2018 11:03:01 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r330577 - stable/11/contrib/ldns-host
Message-ID:  <201803071103.w27B31Rh042786@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Mar  7 11:03:01 2018
New Revision: 330577
URL: https://svnweb.freebsd.org/changeset/base/330577

Log:
  MFC r302779,r302807:
  
  merge upstream hg 06347b1f76fe (fix IXFR)
  
  Initialize first_serial to 0 in dozonetransfer(..) to fix -Wuninitialized
  warning
  
  PR:	209177

Modified:
  stable/11/contrib/ldns-host/ldns-host.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/ldns-host/ldns-host.c
==============================================================================
--- stable/11/contrib/ldns-host/ldns-host.c	Wed Mar  7 10:54:10 2018	(r330576)
+++ stable/11/contrib/ldns-host/ldns-host.c	Wed Mar  7 11:03:01 2018	(r330577)
@@ -156,6 +156,19 @@ memerr:
     return LDNS_STATUS_MEM_ERR;
 }
 
+static uint32_t
+ldns_rr_soa_get_serial(const ldns_rr *rr)
+{
+    const ldns_rdf *rdf;
+  
+    if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) return 0;
+    if (ldns_rr_rd_count(rr) != 7) return 0;
+    rdf = ldns_rr_rdf(rr, 2);
+    if (ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_INT32) return 0;
+    if (ldns_rdf_size(rdf) != 4) return 0;
+    return ldns_rdf2native_int32(rdf);
+}
+
 static ldns_status
 ldns_tcp_start(ldns_resolver *res, ldns_pkt *qpkt, int nameserver) {
     /* This routine is based on ldns_axfr_start, with the major
@@ -873,18 +886,16 @@ dozonetransfer(ldns_resolver *res, ldns_rdf *domain, b
     ldns_rdf *dname;
     ldns_rr_type rrtype;
     ldns_rr_list *rrl;
-    int i, nsoa = 0;
+    ldns_rr *rr;
+    size_t i, nsoa = 0;
+    uint32_t first_serial = 0;
 
     rrtype = o_rrtype;
     o_rrtype = (o_mode == M_AXFR) ? LDNS_RR_TYPE_AXFR : LDNS_RR_TYPE_IXFR;
     dname = search(res, domain, &pkt, absolute, false);
 
     for (;;) {
-        rrl = ldns_pkt_answer(pkt);
-        for (i = ldns_rr_list_rr_count(rrl) - 1; i >= 0; i--) {
-            if (ldns_rr_get_type(ldns_rr_list_rr(rrl, i)) == LDNS_RR_TYPE_SOA)
-                nsoa++;
-        }
+        rrl = ldns_rr_list_clone(ldns_pkt_answer(pkt));
         ldns_pkt_filter_answer(pkt, rrtype);
         report(res, dname != NULL ? dname : domain, pkt);
         if ((dname == NULL) ||
@@ -893,9 +904,29 @@ dozonetransfer(ldns_resolver *res, ldns_rdf *domain, b
             ldns_tcp_close(res);
             return false;
         }
-        if (nsoa >= 2) {
-            ldns_tcp_close(res);
-            return true;
+        for (i = 0; i < ldns_rr_list_rr_count(rrl); i++) {
+            rr = ldns_rr_list_rr(rrl, i);
+            if (nsoa == 0) {
+                if (ldns_rr_get_type(rr) != LDNS_RR_TYPE_SOA) {
+                    printf("; Transfer failed. "
+                           "Didn't start with SOA answer.\n");
+                    ldns_tcp_close(res);
+                    return false;
+                }
+                first_serial = ldns_rr_soa_get_serial(rr);
+                if ((o_mode == M_IXFR) && (first_serial <= o_ixfr_serial)) {
+                    ldns_tcp_close(res);
+                    return true;
+                }
+            }
+            if (ldns_rr_get_type(rr) == LDNS_RR_TYPE_SOA) {
+                nsoa = nsoa < 2 ? nsoa + 1 : 1;
+                if ((nsoa == 2) &&
+                        (ldns_rr_soa_get_serial(rr) == first_serial)) {
+                    ldns_tcp_close(res);
+                    return true;
+                }
+            }
         }
         if (ldns_tcp_read(&nextpkt, res) != LDNS_STATUS_OK) {
             printf("; Transfer failed.\n");
@@ -904,6 +935,7 @@ dozonetransfer(ldns_resolver *res, ldns_rdf *domain, b
         ldns_pkt_set_answerfrom(nextpkt,
                 ldns_rdf_clone(ldns_pkt_answerfrom(pkt)));
         ldns_pkt_free(pkt);
+        ldns_rr_list_free(rrl);
         pkt = nextpkt;
     }
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803071103.w27B31Rh042786>