From: Mark Andrews Date: Sat, 27 Sep 2014 01:41:44 +0000 (+1000) Subject: 3952. [bug] dns_name_fullcompare failed to set *nlabelsp when the X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62b32918d76c1680e3e22346bc4e185c86a6086c;p=thirdparty%2Fbind9.git 3952. [bug] dns_name_fullcompare failed to set *nlabelsp when the two name pointers were the same. [RT #37176] (cherry picked from commit a266ab205bfd1c510022e2cd2a8cb62988242593) --- diff --git a/CHANGES b/CHANGES index 709d4b357c8..6b8a306c305 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3952. [bug] dns_name_fullcompare failed to set *nlabelsp when the + two name pointers were the same. [RT #37176] + --- 9.8.8 released --- --- 9.8.8rc2 released --- diff --git a/lib/dns/name.c b/lib/dns/name.c index 5207f74b424..3b7ff3f962b 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -579,6 +579,7 @@ dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2, if (name1 == name2) { *orderp = 0; + *nlabelsp = name1->labels; return (dns_namereln_equal); } diff --git a/lib/dns/tests/Makefile.in b/lib/dns/tests/Makefile.in index 1e59930bfa6..c1bb72aaed3 100644 --- a/lib/dns/tests/Makefile.in +++ b/lib/dns/tests/Makefile.in @@ -42,6 +42,7 @@ SRCS = db_test.c \ dbversion_test.c \ dnstest.c \ master_test.c \ + name_test.c \ nsec3_test.c \ rdata_test.c \ rdataset_test.c \ @@ -53,6 +54,7 @@ TARGETS = db_test@EXEEXT@ \ dbiterator_test@EXEEXT@ \ dbversion_test@EXEEXT@ \ master_test@EXEEXT@ \ + name_test@EXEEXT@ \ nsec3_test@EXEEXT@ \ rdata_test@EXEEXT@ \ rdataset_test@EXEEXT@ \ @@ -86,6 +88,11 @@ dbversion_test@EXEEXT@: dbversion_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIB dbversion_test.@O@ dnstest.@O@ ${DNSLIBS} \ ${ISCLIBS} ${LIBS} +name_test@EXEEXT@: name_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ + name_test.@O@ dnstest.@O@ ${DNSLIBS} \ + ${ISCLIBS} ${LIBS} + nsec3_test@EXEEXT@: nsec3_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ nsec3_test.@O@ dnstest.@O@ ${DNSLIBS} \ diff --git a/lib/dns/tests/name_test.c b/lib/dns/tests/name_test.c new file mode 100644 index 00000000000..ec264feea29 --- /dev/null +++ b/lib/dns/tests/name_test.c @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2012, 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. + */ + +/* $Id$ */ + +/*! \file */ + +#include + +#include + +#include + +#include +#include +#include "dnstest.h" + +/* + * Individual unit tests + */ + +ATF_TC(fullcompare); +ATF_TC_HEAD(fullcompare, tc) { + atf_tc_set_md_var(tc, "descr", "dns_name_fullcompare test"); +} +ATF_TC_BODY(fullcompare, tc) { + dns_fixedname_t fixed1; + dns_fixedname_t fixed2; + dns_name_t *name1; + dns_name_t *name2; + dns_namereln_t relation; + int i; + isc_result_t result; + struct { + const char *name1; + const char *name2; + dns_namereln_t relation; + int order; + unsigned int nlabels; + } data[] = { + /* relative */ + { "", "", dns_namereln_equal, 0, 0 }, + { "foo", "", dns_namereln_subdomain, 1, 0 }, + { "", "foo", dns_namereln_contains, -1, 0 }, + { "foo", "bar", dns_namereln_none, 4, 0 }, + { "bar", "foo", dns_namereln_none, -4, 0 }, + { "bar.foo", "foo", dns_namereln_subdomain, 1, 1 }, + { "foo", "bar.foo", dns_namereln_contains, -1, 1 }, + { "baz.bar.foo", "bar.foo", dns_namereln_subdomain, 1, 2 }, + { "bar.foo", "baz.bar.foo", dns_namereln_contains, -1, 2 }, + { "foo.example", "bar.example", dns_namereln_commonancestor, + 4, 1 }, + + /* absolute */ + { ".", ".", dns_namereln_equal, 0, 1 }, + { "foo.", "bar.", dns_namereln_commonancestor, 4, 1 }, + { "bar.", "foo.", dns_namereln_commonancestor, -4, 1 }, + { "foo.example.", "bar.example.", dns_namereln_commonancestor, + 4, 2 }, + { "bar.foo.", "foo.", dns_namereln_subdomain, 1, 2 }, + { "foo.", "bar.foo.", dns_namereln_contains, -1, 2 }, + { "baz.bar.foo.", "bar.foo.", dns_namereln_subdomain, 1, 3 }, + { "bar.foo.", "baz.bar.foo.", dns_namereln_contains, -1, 3 }, + { NULL, NULL, dns_namereln_none, 0, 0 } + }; + + UNUSED(tc); + + dns_fixedname_init(&fixed1); + name1 = dns_fixedname_name(&fixed1); + dns_fixedname_init(&fixed2); + name2 = dns_fixedname_name(&fixed2); + for (i = 0; data[i].name1 != NULL; i++) { + int order = 3000; + unsigned int nlabels = 3000; + + if (data[i].name1[0] == 0) { + dns_fixedname_init(&fixed1); + } else { + result = dns_name_fromstring2(name1, data[i].name1, + NULL, 0, NULL); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + } + if (data[i].name2[0] == 0) { + dns_fixedname_init(&fixed2); + } else { + result = dns_name_fromstring2(name2, data[i].name2, + NULL, 0, NULL); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + } + relation = dns_name_fullcompare(name1, name1, &order, &nlabels); + ATF_REQUIRE_EQ(relation, dns_namereln_equal); + ATF_REQUIRE_EQ(order, 0); + ATF_REQUIRE_EQ(nlabels, name1->labels); + + /* Some random initializer */ + order = 3001; + nlabels = 3001; + + relation = dns_name_fullcompare(name1, name2, &order, &nlabels); + ATF_REQUIRE_EQ(relation, data[i].relation); + ATF_REQUIRE_EQ(order, data[i].order); + ATF_REQUIRE_EQ(nlabels, data[i].nlabels); + } +} + +/* + * Main + */ +ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, fullcompare); + + return (atf_no_error()); +} +