From owner-svn-src-all@freebsd.org Wed Mar 7 11:03:02 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4B126F458C2; Wed, 7 Mar 2018 11:03:02 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DF5086CB86; Wed, 7 Mar 2018 11:03:01 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D527120890; Wed, 7 Mar 2018 11:03:01 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w27B31KE042787; Wed, 7 Mar 2018 11:03:01 GMT (envelope-from eadler@FreeBSD.org) Received: (from eadler@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w27B31Rh042786; Wed, 7 Mar 2018 11:03:01 GMT (envelope-from eadler@FreeBSD.org) Message-Id: <201803071103.w27B31Rh042786@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eadler set sender to eadler@FreeBSD.org using -f From: Eitan Adler Date: Wed, 7 Mar 2018 11:03:01 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: eadler X-SVN-Commit-Paths: stable/11/contrib/ldns-host X-SVN-Commit-Revision: 330577 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Mar 2018 11:03:02 -0000 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; } }