From d7d9376e61b5ae66a11a74199a2cf2e19a81981f Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 3 May 2017 07:51:41 +1000 Subject: [PATCH] 4615. [bug] AD could be set on truncated answer with no records present in the answer and authority sections. [RT #45140] (cherry picked from commit 33e94f501f32955e1c44bcd4015459dc9c95ccb0) --- CHANGES | 4 ++++ .../system/resolver/ns6/ds.example.net.db.in | 12 ++++++++++++ bin/tests/system/resolver/ns6/keygen.sh | 9 +++++++++ bin/tests/system/resolver/ns6/named.conf | 6 ++++++ bin/tests/system/resolver/tests.sh | 16 ++++++++++++++++ lib/dns/message.c | 10 ++++++++++ 6 files changed, 57 insertions(+) create mode 100644 bin/tests/system/resolver/ns6/ds.example.net.db.in diff --git a/CHANGES b/CHANGES index a5091a7dfc..6daab2375c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +4615. [bug] AD could be set on truncated answer with no records + present in the answer and authority sections. + [RT #45140] + 4614. [test] Fixed an error in the sockaddr unit test. [RT #45146] 4612. [bug] Silence 'may be use uninitalised' warning and simplify diff --git a/bin/tests/system/resolver/ns6/ds.example.net.db.in b/bin/tests/system/resolver/ns6/ds.example.net.db.in new file mode 100644 index 0000000000..902bb49976 --- /dev/null +++ b/bin/tests/system/resolver/ns6/ds.example.net.db.in @@ -0,0 +1,12 @@ +; Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC") +; +; This Source Code Form is subject to the terms of the Mozilla Public +; License, v. 2.0. If a copy of the MPL was not distributed with this +; file, You can obtain one at http://mozilla.org/MPL/2.0/. + +; $Id: example.net.db.in,v 1.3 2010/11/17 23:47:08 tbox Exp $ + +$TTL 600 +@ IN SOA ns hostmaster 1 1800 900 604800 600 +@ IN NS ns +ns IN A 10.53.0.6 diff --git a/bin/tests/system/resolver/ns6/keygen.sh b/bin/tests/system/resolver/ns6/keygen.sh index 8236ff189c..6b173e66a4 100644 --- a/bin/tests/system/resolver/ns6/keygen.sh +++ b/bin/tests/system/resolver/ns6/keygen.sh @@ -19,6 +19,15 @@ SYSTEMTESTTOP=../.. . $SYSTEMTESTTOP/conf.sh +zone=ds.example.net +zonefile="${zone}.db" +infile="${zonefile}.in" +cp $infile $zonefile +ksk=`$KEYGEN -q -3 -r $RANDFILE -fk $zone` +zsk=`$KEYGEN -q -3 -r $RANDFILE -b 2048 $zone` +cat $ksk.key $zsk.key >> $zonefile +$SIGNER -P -r $RANDFILE -o $zone $zonefile > /dev/null 2>&1 + zone=example.net zonefile="${zone}.db" infile="${zonefile}.in" diff --git a/bin/tests/system/resolver/ns6/named.conf b/bin/tests/system/resolver/ns6/named.conf index cfb32b6959..858f916c0e 100644 --- a/bin/tests/system/resolver/ns6/named.conf +++ b/bin/tests/system/resolver/ns6/named.conf @@ -37,6 +37,12 @@ options { root-delegation-only exclude { "a"; }; }; +zone "ds.example.net" { + type master; + file "ds.example.net.db.signed"; + allow-update { any; }; +}; + zone "." { type master; file "root.db"; diff --git a/bin/tests/system/resolver/tests.sh b/bin/tests/system/resolver/tests.sh index e8abc349a3..3a8a95c109 100755 --- a/bin/tests/system/resolver/tests.sh +++ b/bin/tests/system/resolver/tests.sh @@ -574,5 +574,21 @@ test ${ttl:-1} -eq 0 || ret=1 if [ $ret != 0 ]; then echo "I:failed"; fi status=`expr $status + $ret` +n=`expr $n + 1` +echo "I:check that 'ad' in not returned in truncated answer with empty answer and authority sections to request with +ad (${n})" +ret=0 +$DIG @10.53.0.6 -p 5300 dnskey ds.example.net +bufsize=512 +ad +nodnssec +ignore +norec > dig.out.$n +grep "flags: qr aa tc; QUERY: 1, ANSWER: 0, AUTHORITY: 0" dig.out.$n > /dev/null || ret=1 +if [ $ret != 0 ]; then echo "I:failed"; fi +status=`expr $status + $ret` + +n=`expr $n + 1` +echo "I:check that 'ad' in not returned in truncated answer with empty answer and authority sections to request with +dnssec (${n})" +ret=0 +$DIG @10.53.0.6 -p 5300 dnskey ds.example.net +bufsize=512 +noad +dnssec +ignore +norec > dig.out.$n +grep "flags: qr aa tc; QUERY: 1, ANSWER: 0, AUTHORITY: 0" dig.out.$n > /dev/null || ret=1 +if [ $ret != 0 ]; then echo "I:failed"; fi +status=`expr $status + $ret` + echo "I:exit status: $status" [ $status -eq 0 ] || exit 1 diff --git a/lib/dns/message.c b/lib/dns/message.c index 5c7ca2067f..8b09745b6d 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -1956,6 +1956,15 @@ renderset(dns_rdataset_t *rdataset, dns_name_t *owner_name, return (result); } +static void +maybe_clear_ad(dns_message_t *msg, dns_section_t sectionid) { + if (msg->counts[sectionid] == 0 && + (sectionid == DNS_SECTION_ANSWER || + (sectionid == DNS_SECTION_AUTHORITY && + msg->counts[DNS_SECTION_ANSWER] == 0))) + msg->flags &= ~DNS_MESSAGEFLAG_AD; +} + isc_result_t dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, unsigned int options) @@ -2153,6 +2162,7 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, *(msg->buffer) = st; /* rollback */ msg->buffer->length += msg->reserved; msg->counts[sectionid] += total; + maybe_clear_ad(msg, sectionid); return (result); }