From: Mark Andrews Date: Thu, 16 Jan 2014 23:04:16 +0000 (+1100) Subject: 3710. [bug] Address double dns_zone_detach when switching to X-Git-Tag: v9.6-ESV-R11rc2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f24c02e955c9ca1481000b452d3244b1ee7d426e;p=thirdparty%2Fbind9.git 3710. [bug] Address double dns_zone_detach when switching to using automatic empty zones from regular zones. [RT #35177] (cherry picked from commit db8938c993d3eaeae1d86feb1b5da511831a9014) --- diff --git a/CHANGES b/CHANGES index f59b64a52f2..34679122217 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +3710. [bug] Address double dns_zone_detach when switching to + using automatic empty zones from regular zones. + [RT #35177] + 3706. [contrib] queryperf: Fixed a possible integer overflow when printing results. [RT #35182] diff --git a/bin/named/server.c b/bin/named/server.c index 8a26037f1cf..998a80eeced 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -990,26 +990,22 @@ on_disable_list(const cfg_obj_t *disablelist, dns_name_t *zonename) { return (ISC_FALSE); } -static void -check_dbtype(dns_zone_t **zonep, unsigned int dbtypec, const char **dbargv, +static isc_result_t +check_dbtype(dns_zone_t *zone, unsigned int dbtypec, const char **dbargv, isc_mem_t *mctx) { char **argv = NULL; unsigned int i; - isc_result_t result; + isc_result_t result = ISC_R_SUCCESS; - result = dns_zone_getdbtype(*zonep, &argv, mctx); - if (result != ISC_R_SUCCESS) { - dns_zone_detach(zonep); - return; - } + CHECK(dns_zone_getdbtype(zone, &argv, mctx)); /* * Check that all the arguments match. */ for (i = 0; i < dbtypec; i++) if (argv[i] == NULL || strcmp(argv[i], dbargv[i]) != 0) { - dns_zone_detach(zonep); + CHECK(ISC_R_FAILURE); break; } @@ -1017,8 +1013,11 @@ check_dbtype(dns_zone_t **zonep, unsigned int dbtypec, const char **dbargv, * Check that there are not extra arguments. */ if (i == dbtypec && argv[i] != NULL) - dns_zone_detach(zonep); + result = ISC_R_FAILURE; + + cleanup: isc_mem_free(mctx, argv); + return (result); } static isc_result_t @@ -1228,12 +1227,21 @@ create_empty_zone(dns_zone_t *zone, dns_name_t *name, dns_view_t *view, * Is the existing zone the ok to use? */ if (zone != NULL) { - if (db != NULL) - check_dbtype(&zone, rbt_dbtypec, rbt_dbtype, - view->mctx); - else - check_dbtype(&zone, empty_dbtypec, empty_dbtype, - view->mctx); + unsigned int typec; + const char **dbargv; + + if (db != NULL) { + typec = rbt_dbtypec; + dbargv = rbt_dbtype; + } else { + typec = empty_dbtypec; + dbargv = empty_dbtype; + } + + result = check_dbtype(zone, typec, dbargv, view->mctx); + if (result != ISC_R_SUCCESS) + zone = NULL; + if (zone != NULL && dns_zone_gettype(zone) != dns_zone_master) zone = NULL; if (zone != NULL && dns_zone_getfile(zone) != NULL) diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in index 1a6d1537965..bdea347caff 100644 --- a/bin/tests/system/conf.sh.in +++ b/bin/tests/system/conf.sh.in @@ -44,7 +44,9 @@ CHECKCONF=$TOP/bin/check/named-checkconf # load on the machine to make it unusable to other users. # v6synth SUBDIRS="acl additional allow_query builtin cacheclean case checkconf - checknames checkzone database dlv dlz dname dnssec formerr + checknames checkzone database dlv dlz dname dnssec + emptyzones + formerr forward glue ixfr limits logfileconfig lwresd masterfile masterformat notify nsupdate pending resolver rndc rrsetorder spf sortlist stub tkey unknown upforwd views wildcard xfer diff --git a/bin/tests/system/emptyzones/clean.sh b/bin/tests/system/emptyzones/clean.sh new file mode 100644 index 00000000000..66b3a17fa7e --- /dev/null +++ b/bin/tests/system/emptyzones/clean.sh @@ -0,0 +1 @@ +rm -f ns1/named.conf diff --git a/bin/tests/system/emptyzones/ns1/empty.db b/bin/tests/system/emptyzones/ns1/empty.db new file mode 100644 index 00000000000..d807099a4b3 --- /dev/null +++ b/bin/tests/system/emptyzones/ns1/empty.db @@ -0,0 +1,16 @@ +; Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") +; +; Permission to use, copy, modify, and/or distribute this software for any +; purpose with or without fee is hereby granted, provided that the above +; copyright notice and this permission notice appear in all copies. +; +; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +; AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +; PERFORMANCE OF THIS SOFTWARE. + +@ 0 SOA . . 0 0 0 0 0 +@ 0 NS . diff --git a/bin/tests/system/emptyzones/ns1/named1.conf b/bin/tests/system/emptyzones/ns1/named1.conf new file mode 100644 index 00000000000..6f54ad24c77 --- /dev/null +++ b/bin/tests/system/emptyzones/ns1/named1.conf @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2004, 2007, 2009, 2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: named.conf,v 1.15 2009/05/29 23:47:49 tbox Exp $ */ + +key rndc_key { + algorithm hmac-sha256; + secret "1234abcd8765"; +}; + +controls { + inet 10.53.0.1 port 9953 allow { any; } keys { rndc_key; }; +}; + +options { + query-source address 10.53.0.1 dscp 1; + notify-source 10.53.0.1 dscp 2; + transfer-source 10.53.0.1 dscp 3; + port 5300; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + listen-on-v6 { none; }; + recursion yes; + acache-enable yes; + deny-answer-addresses { 192.0.2.0/24; 2001:db8:beef::/48; } + except-from { "example.org"; }; + deny-answer-aliases { "example.org"; } + except-from { "goodcname.example.net"; + "gooddname.example.net"; }; + allow-query {!10.53.0.8; any; }; +}; + +zone "." { + type hint; + file "root.hint"; +}; + +include "rfc1918.zones"; diff --git a/bin/tests/system/emptyzones/ns1/named2.conf b/bin/tests/system/emptyzones/ns1/named2.conf new file mode 100644 index 00000000000..467511ca220 --- /dev/null +++ b/bin/tests/system/emptyzones/ns1/named2.conf @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2004, 2007, 2009, 2013 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2000, 2001 Internet Software Consortium. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, + * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* $Id: named.conf,v 1.15 2009/05/29 23:47:49 tbox Exp $ */ + +key rndc_key { + algorithm hmac-sha256; + secret "1234abcd8765"; +}; + +controls { + inet 10.53.0.1 port 9953 allow { any; } keys { rndc_key; }; +}; + +options { + query-source address 10.53.0.1 dscp 1; + notify-source 10.53.0.1 dscp 2; + transfer-source 10.53.0.1 dscp 3; + port 5300; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + listen-on-v6 { none; }; + recursion yes; + acache-enable yes; + deny-answer-addresses { 192.0.2.0/24; 2001:db8:beef::/48; } + except-from { "example.org"; }; + deny-answer-aliases { "example.org"; } + except-from { "goodcname.example.net"; + "gooddname.example.net"; }; + allow-query {!10.53.0.8; any; }; +}; + +zone "." { + type hint; + file "root.hint"; +}; diff --git a/bin/tests/system/emptyzones/ns1/rfc1918.zones b/bin/tests/system/emptyzones/ns1/rfc1918.zones new file mode 100644 index 00000000000..e2f4ac4c744 --- /dev/null +++ b/bin/tests/system/emptyzones/ns1/rfc1918.zones @@ -0,0 +1,19 @@ +zone "10.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "16.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "17.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "18.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "19.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "20.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "21.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "22.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "23.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "24.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "25.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "26.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "27.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "28.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "29.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "30.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "31.172.IN-ADDR.ARPA" { type master; file "empty.db"; }; +zone "168.192.IN-ADDR.ARPA" { type master; file "empty.db"; }; + diff --git a/bin/tests/system/emptyzones/ns1/root.hint b/bin/tests/system/emptyzones/ns1/root.hint new file mode 100644 index 00000000000..2fd180e3ba7 --- /dev/null +++ b/bin/tests/system/emptyzones/ns1/root.hint @@ -0,0 +1,20 @@ +; Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +; Copyright (C) 2000, 2001 Internet Software Consortium. +; +; Permission to use, copy, modify, and/or distribute this software for any +; purpose with or without fee is hereby granted, provided that the above +; copyright notice and this permission notice appear in all copies. +; +; THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +; REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +; AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +; INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +; LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +; OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +; PERFORMANCE OF THIS SOFTWARE. + +; $Id: root.hint,v 1.7 2007/06/19 23:47:05 tbox Exp $ + +$TTL 999999 +. IN NS a.root-servers.nil. +a.root-servers.nil. IN A 10.53.0.2 diff --git a/bin/tests/system/emptyzones/setup.sh b/bin/tests/system/emptyzones/setup.sh new file mode 100644 index 00000000000..1faa70e3081 --- /dev/null +++ b/bin/tests/system/emptyzones/setup.sh @@ -0,0 +1 @@ +cp -f ns1/named1.conf ns1/named.conf diff --git a/bin/tests/system/emptyzones/tests.sh b/bin/tests/system/emptyzones/tests.sh new file mode 100644 index 00000000000..755d89d56fc --- /dev/null +++ b/bin/tests/system/emptyzones/tests.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +SYSTEMTESTTOP=.. +. $SYSTEMTESTTOP/conf.sh + +status=0 +n=0 + +n=`expr $n + 1` +echo "I:check that switching to automatic empty zones works ($n)" +ret=0 +$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 reload > /dev/null || ret=1 +sleep 5 +cp ns1/named2.conf ns1/named.conf +$RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 reload > /dev/null || ret=1 +sleep 5 +$DIG +vc version.bind txt ch @10.53.0.1 -p 5300 > /dev/null || ret=1 +if [ $ret != 0 ]; then echo "I:failed"; fi +status=`expr $status + $ret` + +exit $status