]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
3998. [bug] isc_radix_search was returning matches that were
authorMark Andrews <marka@isc.org>
Tue, 4 Nov 2014 01:34:12 +0000 (12:34 +1100)
committerMark Andrews <marka@isc.org>
Tue, 4 Nov 2014 01:34:12 +0000 (12:34 +1100)
                        to precise. [RT #37680]

CHANGES
lib/isc/include/isc/radix.h
lib/isc/radix.c
lib/isc/tests/Makefile.in
lib/isc/tests/radix_test.c [new file with mode: 0644]

diff --git a/CHANGES b/CHANGES
index 8fa1abbf710c402343f46bc2fe5ac1fb2487bc8d..debf8e9f2aa46da517875a311f3c56dc83fb1239 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+3998.  [bug]           isc_radix_search was returning matches that were
+                       to precise. [RT #37680]
+
 3997.  [protocol]      Add OPENGPGKEY record. [RT# 37671]
 
 3996.  [bug]           Address use after free on out of memory error in
index 4d0b3b08f1ae20be410086ccd2eb80b4126c0708..24c183f2c2150b2b05b58950c135294e1dcde116 100644 (file)
@@ -32,7 +32,7 @@
 #ifndef _RADIX_H
 #define _RADIX_H
 
-#define NETADDR_TO_PREFIX_T(na,pt,bits,isecs) \
+#define NETADDR_TO_PREFIX_T(na,pt,bits,is_ecs) \
        do { \
                memset(&(pt), 0, sizeof(pt)); \
                if((na) != NULL) { \
@@ -48,7 +48,7 @@
                        (pt).family = AF_UNSPEC; \
                        (pt).bitlen = 0; \
                } \
-               (pt).ecs = isecs; \
+               (pt).ecs = is_ecs; \
                isc_refcount_init(&(pt).refcount, 0); \
        } while(0)
 
index 47e13b7856667e99fecc5049207187f1fadbc217..a1d8235d94b88f45e86d44241f6665baf073d6db 100644 (file)
@@ -280,6 +280,9 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
        while (cnt-- > 0) {
                node = stack[cnt];
 
+               if (prefix->bitlen < node->bit)
+                       continue;
+
                if (_comp_with_mask(isc_prefix_tochar(node->prefix),
                                    isc_prefix_tochar(prefix),
                                    node->prefix->bitlen))
index e1125b0b7e3d9d3036bde7362754485eecf5fc7a..bc21d4a2c4f68534bead64d81ce13618d01490a3 100644 (file)
@@ -36,14 +36,14 @@ LIBS =              @LIBS@ @ATFLIBS@
 
 OBJS =         isctest.@O@
 SRCS =         isctest.c taskpool_test.c socket_test.c hash_test.c \
-               lex_test.c random_test.c \
+               lex_test.c radix_test.c random_test.c \
                sockaddr_test.c symtab_test.c task_test.c queue_test.c \
                parse_test.c pool_test.c print_test.c regex_test.c \
                socket_test.c safe_test.c time_test.c aes_test.c
 
 SUBDIRS =
 TARGETS =      taskpool_test@EXEEXT@ socket_test@EXEEXT@ hash_test@EXEEXT@ \
-               lex_test@EXEEXT@ random_test@EXEEXT@ \
+               lex_test@EXEEXT@ radix_test@EXEEXT@ random_test@EXEEXT@ \
                sockaddr_test@EXEEXT@ symtab_test@EXEEXT@ task_test@EXEEXT@ \
                queue_test@EXEEXT@ parse_test@EXEEXT@ pool_test@EXEEXT@ \
                print_test@EXEEXT@ regex_test@EXEEXT@ socket_test@EXEEXT@ \
@@ -75,6 +75,10 @@ queue_test@EXEEXT@: queue_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
                        queue_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
 
+radix_test@EXEEXT@: radix_test.@O@ isctest.@O@ ${ISCDEPLIBS}
+       ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
+                       radix_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
+
 random_test@EXEEXT@: random_test.@O@ isctest.@O@ ${ISCDEPLIBS}
        ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
                        random_test.@O@ isctest.@O@ ${ISCLIBS} ${LIBS}
diff --git a/lib/isc/tests/radix_test.c b/lib/isc/tests/radix_test.c
new file mode 100644 (file)
index 0000000..80d971e
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#include <config.h>
+
+#include <isc/mem.h>
+#include <isc/netaddr.h>
+#include <isc/radix.h>
+#include <isc/result.h>
+#include <isc/util.h>
+
+#include <atf-c.h>
+
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "isctest.h"
+
+ATF_TC(isc_radix_search);
+ATF_TC_HEAD(isc_radix_search, tc) {
+       atf_tc_set_md_var(tc, "descr", "test radix seaching");
+}
+ATF_TC_BODY(isc_radix_search, tc) {
+       isc_radix_tree_t *radix = NULL;
+       isc_radix_node_t *node;
+       isc_prefix_t prefix;
+       isc_result_t result;
+       struct in_addr in_addr;
+       isc_netaddr_t netaddr;
+
+       UNUSED(tc);
+
+       result = isc_test_begin(NULL, ISC_TRUE);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       result = isc_radix_create(mctx, &radix, 32);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       in_addr.s_addr = inet_addr("3.3.3.0");
+       isc_netaddr_fromin(&netaddr, &in_addr);
+       NETADDR_TO_PREFIX_T(&netaddr, prefix, 24, ISC_FALSE);
+
+       node = NULL;
+       result = isc_radix_insert(radix, &node, NULL, &prefix);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       node->data[0] = (void *)1;
+       isc_refcount_destroy(&prefix.refcount);
+
+       in_addr.s_addr = inet_addr("3.3.0.0");
+       isc_netaddr_fromin(&netaddr, &in_addr);
+       NETADDR_TO_PREFIX_T(&netaddr, prefix, 16, ISC_FALSE);
+
+       node = NULL;
+       result = isc_radix_insert(radix, &node, NULL, &prefix);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       node->data[0] = (void *)2;
+       isc_refcount_destroy(&prefix.refcount);
+
+       in_addr.s_addr = inet_addr("3.3.3.3");
+       isc_netaddr_fromin(&netaddr, &in_addr);
+       NETADDR_TO_PREFIX_T(&netaddr, prefix, 22, ISC_FALSE);
+
+       node = NULL;
+       result = isc_radix_search(radix, &node, &prefix);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+       ATF_REQUIRE_EQ(node->data[0], (void *)2);
+
+       isc_refcount_destroy(&prefix.refcount);
+
+       isc_radix_destroy(radix, NULL);
+
+       isc_test_end();
+}
+
+/*
+ * Main
+ */
+ATF_TP_ADD_TCS(tp) {
+       ATF_TP_ADD_TC(tp, isc_radix_search);
+
+       return (atf_no_error());
+}