From 8dc862fe22e124af5c2ac677ba08274b7cd5b9ce Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Fri, 10 Aug 2012 20:23:57 -0700 Subject: [PATCH] address memory leak with bad tsig secret 3359. [bug] An improperly-formed TSIG secret could cause a memory leak. [RT #30607] --- CHANGES | 5 ++++- bin/tests/system/checkconf/badtsig.conf | 22 ++++++++++++++++++++++ bin/tests/system/checkconf/tests.sh | 7 ++++++- lib/bind9/check.c | 13 ++++++++----- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 bin/tests/system/checkconf/badtsig.conf diff --git a/CHANGES b/CHANGES index 25514ff2e3..cafbfebff4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ -3358 [bug] Fix declaration of fatal in bin/named/server.c +3359. [bug] An improperly-formed TSIG secret could cause a + memory leak. [RT #30607] + +3358. [bug] Fix declaration of fatal in bin/named/server.c and bin/nsupdate/main.c. [RT #30522] 3357. [port] Add support for libxml2-2.8.x [RT #30440] diff --git a/bin/tests/system/checkconf/badtsig.conf b/bin/tests/system/checkconf/badtsig.conf new file mode 100644 index 0000000000..9585b11937 --- /dev/null +++ b/bin/tests/system/checkconf/badtsig.conf @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 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. + */ + +/* Bad secret */ +key "badtsig" { + algorithm hmac-md5; + secret "jEdD+BPKg=="; +}; + diff --git a/bin/tests/system/checkconf/tests.sh b/bin/tests/system/checkconf/tests.sh index 3c4feb795b..5766d8c8c3 100644 --- a/bin/tests/system/checkconf/tests.sh +++ b/bin/tests/system/checkconf/tests.sh @@ -27,11 +27,16 @@ if [ $ret != 0 ]; then echo "I:failed"; fi status=`expr $status + $ret` echo "I: checking that named-checkconf handles a known bad config" - ret=1 $CHECKCONF bad.conf > /dev/null 2>&1 || ret=0 if [ $ret != 0 ]; then echo "I:failed"; fi status=`expr $status + $ret` +echo "I: checking that named-checkconf handles a known bad tsig secret" +ret=0 +$CHECKCONF badtsig.conf > /dev/null 2>&1 +if [ $? != 1 ]; then echo "I:failed"; ret=1; fi +status=`expr $status + $ret` + echo "I:exit status: $status" exit $status diff --git a/lib/bind9/check.c b/lib/bind9/check.c index 6ffa8d7c75..81294a3dec 100644 --- a/lib/bind9/check.c +++ b/lib/bind9/check.c @@ -1834,15 +1834,15 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, tresult = isc_symtab_create(mctx, 1000, freekey, mctx, ISC_FALSE, &symtab); if (tresult != ISC_R_SUCCESS) - return (ISC_R_NOMEMORY); + goto cleanup; (void)cfg_map_get(config, "key", &keys); tresult = check_keylist(keys, symtab, mctx, logctx); if (tresult == ISC_R_EXISTS) result = ISC_R_FAILURE; else if (tresult != ISC_R_SUCCESS) { - isc_symtab_destroy(&symtab); - return (tresult); + result = tresult; + goto cleanup; } if (voptions != NULL) { @@ -1852,8 +1852,8 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, if (tresult == ISC_R_EXISTS) result = ISC_R_FAILURE; else if (tresult != ISC_R_SUCCESS) { - isc_symtab_destroy(&symtab); - return (tresult); + result = tresult; + goto cleanup; } } @@ -1935,6 +1935,9 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, if (tresult != ISC_R_SUCCESS) result = tresult; + cleanup: + if (symtab != NULL) + isc_symtab_destroy(&symtab); cfg_aclconfctx_destroy(&actx); return (result);