]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make isc_radix_insert, dns_iptable_addprefix/merge return void
authorOndřej Surý <ondrej@sury.org>
Sun, 22 Mar 2026 10:06:37 +0000 (11:06 +0100)
committerOndřej Surý <ondrej@sury.org>
Wed, 1 Jul 2026 04:09:42 +0000 (06:09 +0200)
isc_radix_insert can no longer fail: node allocation uses
isc_mem_get which aborts on OOM, and prefix copying was eliminated
by inlining. Propagate the void return through dns_iptable_addprefix,
dns_iptable_merge, dns_acl_any, dns_acl_none, and all their callers.

18 files changed:
bin/named/controlconf.c
bin/named/server.c
bin/named/statschannel.c
bin/named/zoneconf.c
bin/plugins/filter-a.c
bin/plugins/filter-aaaa.c
bin/plugins/synthrecord.c
bin/tests/system/dyndb/driver/zone.c
lib/dns/acl.c
lib/dns/include/dns/acl.h
lib/dns/include/dns/iptable.h
lib/dns/iptable.c
lib/isc/include/isc/radix.h
lib/isc/radix.c
lib/isccfg/aclconf.c
lib/ns/interfacemgr.c
tests/dns/acl_test.c
tests/isc/radix_test.c

index 6a37a49f94803b2b8d127c5e6450324e48d074ee..103f8688abda31b1a09ede6b7215431b7724b6ca 100644 (file)
@@ -964,7 +964,8 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
                result = cfg_acl_fromconfig(allow, config, aclctx,
                                            listener->mctx, 0, &new_acl);
        } else {
-               result = dns_acl_any(listener->mctx, &new_acl);
+               dns_acl_any(listener->mctx, &new_acl);
+               result = ISC_R_SUCCESS;
        }
 
        if (control != NULL) {
@@ -1042,7 +1043,7 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
                        listener->readonly = cfg_obj_asboolean(readonly);
                }
        } else {
-               CHECK(dns_acl_any(mctx, &new_acl));
+               dns_acl_any(mctx, &new_acl);
        }
 
        dns_acl_attach(new_acl, &listener->acl);
index be7ecd02251602659594f0cc9f90faf239b8c571..86e0f961a508782a05a13705ea054ae413c4908a 100644 (file)
@@ -3528,9 +3528,8 @@ cleanup:
 }
 #endif /* HAVE_DNSTAP */
 
-static isc_result_t
+static void
 create_mapped_acl(void) {
-       isc_result_t result;
        dns_acl_t *acl = NULL;
        struct in6_addr in6 = IN6ADDR_V4MAPPED_INIT;
        isc_netaddr_t addr;
@@ -3538,13 +3537,8 @@ create_mapped_acl(void) {
        isc_netaddr_fromin6(&addr, &in6);
 
        dns_acl_create(isc_g_mctx, 1, &acl);
-
-       result = dns_iptable_addprefix(acl->iptable, &addr, 96, true);
-       if (result == ISC_R_SUCCESS) {
-               dns_acl_attach(acl, &named_g_mapped);
-       }
-       dns_acl_detach(&acl);
-       return result;
+       dns_iptable_addprefix(acl->iptable, &addr, 96, true);
+       named_g_mapped = acl;
 }
 
 isc_result_t
@@ -4033,7 +4027,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
                                                         mctx, 0, &excluded));
                        } else {
                                if (named_g_mapped == NULL) {
-                                       CHECK(create_mapped_acl());
+                                       create_mapped_acl();
                                }
                                dns_acl_attach(named_g_mapped, &excluded);
                        }
@@ -6410,7 +6404,7 @@ add_keydata_zone(dns_view_t *view, const char *directory, isc_mem_t *mctx) {
 
        CHECK(dns_zonemgr_managezone(named_g_server->zonemgr, zone));
 
-       CHECK(dns_acl_none(mctx, &none));
+       dns_acl_none(mctx, &none);
        dns_zone_setqueryacl(zone, none);
        dns_zone_setqueryonacl(zone, none);
        dns_acl_detach(&none);
index 2e02cde7ad5de97c254574adfacb6fc196673972..f5a05e7e24b14f8ffdd0caceaa807eb012904f16 100644 (file)
@@ -3843,12 +3843,11 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp,
 
        allow = cfg_tuple_get(listen_params, "allow");
        if (allow != NULL && cfg_obj_islist(allow)) {
-               result = cfg_acl_fromconfig(allow, config, aclctx,
-                                           listener->mctx, 0, &new_acl);
+               CHECK(cfg_acl_fromconfig(allow, config, aclctx, listener->mctx,
+                                        0, &new_acl));
        } else {
-               result = dns_acl_any(listener->mctx, &new_acl);
+               dns_acl_any(listener->mctx, &new_acl);
        }
-       CHECK(result);
 
        dns_acl_attach(new_acl, &listener->acl);
        dns_acl_detach(&new_acl);
@@ -3973,7 +3972,8 @@ update_listener(named_server_t *server, named_statschannel_t **listenerp,
                result = cfg_acl_fromconfig(allow, config, aclctx,
                                            listener->mctx, 0, &new_acl);
        } else {
-               result = dns_acl_any(listener->mctx, &new_acl);
+               dns_acl_any(listener->mctx, &new_acl);
+               result = ISC_R_SUCCESS;
        }
 
        if (result == ISC_R_SUCCESS) {
index 89846353f5709bc33c727bab45337ef68c22b954..64be4515c2acbbd9fbb3091fd2e393c7f33268f1 100644 (file)
@@ -1862,8 +1862,8 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
                obj = NULL;
                (void)named_config_get(nooptions, "allow-transfer", &obj);
                if (obj == NULL) {
-                       dns_acl_t *none;
-                       CHECK(dns_acl_none(mctx, &none));
+                       dns_acl_t *none = NULL;
+                       dns_acl_none(mctx, &none);
                        dns_zone_setxfracl(zone, none);
                        dns_acl_detach(&none);
                }
index f722fdcb813945a29e552ad35c31c7a2efb71b77..d7230cf65ed077e077c270b41127dd56e898875b 100644 (file)
@@ -284,7 +284,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
                                         (cfg_aclconfctx_t *)aclctx, mctx, 0,
                                         &inst->a_acl));
        } else {
-               CHECK(dns_acl_any(mctx, &inst->a_acl));
+               dns_acl_any(mctx, &inst->a_acl);
        }
 
 cleanup:
index 6a7a8d25e9b47c8920db30af2b963cc9af2c5d36..b698ede7a154e5499e229080fbeea6b5bf0c21ae 100644 (file)
@@ -287,7 +287,7 @@ parse_parameters(filter_instance_t *inst, const char *parameters,
                                         (cfg_aclconfctx_t *)aclctx, mctx, 0,
                                         &inst->aaaa_acl));
        } else {
-               CHECK(dns_acl_any(mctx, &inst->aaaa_acl));
+               dns_acl_any(mctx, &inst->aaaa_acl);
        }
 
 cleanup:
index 1825f58452063e05e4f99626f5d1352cfee07c08..9001d8f3be3c0857ef77cfe034b4e20399e29de2 100644 (file)
@@ -512,7 +512,8 @@ synthrecord_parseallowsynth(synthrecord_t *inst, const cfg_obj_t *cfg,
        result = cfg_map_get(synthrecordcfg, "allow-synth", &obj);
 
        if (result == ISC_R_NOTFOUND) {
-               return dns_acl_any(inst->mctx, &inst->allowedsynth);
+               dns_acl_any(inst->mctx, &inst->allowedsynth);
+               return ISC_R_SUCCESS;
        }
 
        if (result != ISC_R_SUCCESS) {
index 37724d44280d2828d9fec0047479229f28ebc942..388aeae975c0c07e5fb2bcb0e9b05d3876457202 100644 (file)
@@ -84,12 +84,7 @@ create_zone(sample_instance_t *const inst, dns_name_t *const name,
        }
 
        /* This is completely insecure - use some sensible values instead! */
-       result = dns_acl_any(inst->mctx, &acl_any);
-       if (result != ISC_R_SUCCESS) {
-               log_write(ISC_LOG_ERROR, "create_zone: dns_acl_any -> %s\n",
-                         isc_result_totext(result));
-               goto cleanup;
-       }
+       dns_acl_any(inst->mctx, &acl_any);
        dns_zone_setupdateacl(raw, acl_any);
        dns_zone_setqueryacl(raw, acl_any);
        dns_zone_setxfracl(raw, acl_any);
index 03c5bb5212bb8c77baa37683a16ac632773e08e1..aa86643fbb0981fdb3747b6feaa4429e29796062 100644 (file)
@@ -61,37 +61,30 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) {
  * "any" is a positive iptable entry with bit length 0.
  * "none" is the same as "!any".
  */
-static isc_result_t
+static void
 dns_acl_anyornone(isc_mem_t *mctx, bool neg, dns_acl_t **target) {
-       isc_result_t result;
        dns_acl_t *acl = NULL;
 
        dns_acl_create(mctx, 0, &acl);
-
-       result = dns_iptable_addprefix(acl->iptable, NULL, 0, !neg);
-       if (result != ISC_R_SUCCESS) {
-               dns_acl_detach(&acl);
-               return result;
-       }
+       dns_iptable_addprefix(acl->iptable, NULL, 0, !neg);
 
        *target = acl;
-       return result;
 }
 
 /*
  * Create a new ACL that matches everything.
  */
-isc_result_t
+void
 dns_acl_any(isc_mem_t *mctx, dns_acl_t **target) {
-       return dns_acl_anyornone(mctx, false, target);
+       dns_acl_anyornone(mctx, false, target);
 }
 
 /*
  * Create a new ACL that matches nothing.
  */
-isc_result_t
+void
 dns_acl_none(isc_mem_t *mctx, dns_acl_t **target) {
-       return dns_acl_anyornone(mctx, true, target);
+       dns_acl_anyornone(mctx, true, target);
 }
 
 /*
@@ -342,7 +335,7 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) {
         * node_count value is set correctly afterward.
         */
        nodes = max_node + dns_acl_node_count(dest);
-       RETERR(dns_iptable_merge(dest->iptable, source->iptable, pos));
+       dns_iptable_merge(dest->iptable, source->iptable, pos);
        if (nodes > dns_acl_node_count(dest)) {
                dns_acl_node_count(dest) = nodes;
        }
index bf11af019f1c4ac89d68afeb3b6f3481900dfca1..4796c43777a4df6224dfdca140c233291d98e2fd 100644 (file)
@@ -125,13 +125,13 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target);
  * length is 0.
  */
 
-isc_result_t
+void
 dns_acl_any(isc_mem_t *mctx, dns_acl_t **target);
 /*%<
  * Create a new ACL that matches everything.
  */
 
-isc_result_t
+void
 dns_acl_none(isc_mem_t *mctx, dns_acl_t **target);
 /*%<
  * Create a new ACL that matches nothing.
index 939e8e723249d298f96c9ccd8a7e913ab5437010..807e1691c6874c4c1f6e0aece9839cc457c3c52a 100644 (file)
@@ -45,14 +45,14 @@ dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target);
  * Create a new IP table and the underlying radix structure
  */
 
-isc_result_t
+void
 dns_iptable_addprefix(dns_iptable_t *tab, const isc_netaddr_t *addr,
                      uint16_t bitlen, bool pos);
 /*
  * Add an IP prefix to an existing IP table
  */
 
-isc_result_t
+void
 dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos);
 /*
  * Merge one IP table into another one.
index 5acd6d05843bc54ed5a770f38b57a0864aba1c24..a2cf2754809c3c4bce07db4bc1609945a963bde9 100644 (file)
@@ -43,30 +43,22 @@ static bool dns_iptable_pos = true;
 /*
  * Add an IP prefix to an existing IP table
  */
-static isc_result_t
+static void
 iptable_addentry(dns_iptable_t *tab, isc_prefix_t *pfx, bool pos) {
        isc_radix_node_t *node = NULL;
-       isc_result_t result;
 
-       result = isc_radix_insert(tab->radix, &node, NULL, pfx);
-       if (result != ISC_R_SUCCESS) {
-               return result;
-       }
+       isc_radix_insert(tab->radix, &node, NULL, pfx);
 
        /* Preserve first-match semantics: don't overwrite existing data */
        int fam = ISC_RADIX_FAMILY(pfx);
        if (node->data[fam] == NULL) {
                node->data[fam] = pos ? &dns_iptable_pos : &dns_iptable_neg;
        }
-
-       return ISC_R_SUCCESS;
 }
 
-isc_result_t
+void
 dns_iptable_addprefix(dns_iptable_t *tab, const isc_netaddr_t *addr,
                      uint16_t bitlen, bool pos) {
-       isc_result_t result;
-
        INSIST(DNS_IPTABLE_VALID(tab));
        INSIST(tab->radix != NULL);
 
@@ -78,29 +70,27 @@ dns_iptable_addprefix(dns_iptable_t *tab, const isc_netaddr_t *addr,
                isc_prefix_t pfx4 = { .family = AF_INET, .bitlen = 0 };
                isc_prefix_t pfx6 = { .family = AF_INET6, .bitlen = 0 };
 
-               result = iptable_addentry(tab, &pfx4, pos);
-               if (result != ISC_R_SUCCESS) {
-                       return result;
-               }
-               return iptable_addentry(tab, &pfx6, pos);
+               iptable_addentry(tab, &pfx4, pos);
+               iptable_addentry(tab, &pfx6, pos);
+               return;
        }
 
        isc_prefix_t pfx;
        NETADDR_TO_PREFIX_T(addr, pfx, bitlen);
-       return iptable_addentry(tab, &pfx, pos);
+       iptable_addentry(tab, &pfx, pos);
 }
 
 /*
  * Merge one IP table into another one.
  */
-isc_result_t
+void
 dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos) {
        isc_radix_node_t *node, *new_node;
-       int i, max_node = 0;
+       int max_node = 0;
 
        RADIX_WALK(source->radix->head, node) {
                new_node = NULL;
-               RETERR(isc_radix_insert(tab->radix, &new_node, node, NULL));
+               isc_radix_insert(tab->radix, &new_node, node, NULL);
 
                /*
                 * If we're negating a nested ACL, then we should
@@ -110,9 +100,11 @@ dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos) {
                 * could be a security risk.  To prevent this, we
                 * just leave the negative nodes negative.
                 */
-               for (i = 0; i < RADIX_FAMILIES; i++) {
+               for (int i = 0; i < RADIX_FAMILIES; i++) {
                        if (!pos) {
-                               if (node->data[i] && *(bool *)node->data[i]) {
+                               if (node->data[i] != NULL &&
+                                   *(bool *)node->data[i])
+                               {
                                        new_node->data[i] = &dns_iptable_neg;
                                }
                        }
@@ -124,7 +116,6 @@ dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos) {
        RADIX_WALK_END;
 
        tab->radix->num_added_node += max_node;
-       return ISC_R_SUCCESS;
 }
 
 static void
index b70160124ff75655c891e48587ae5a7fc84d8959..c5b48532872158d47de5c99ce843f196658a575c 100644 (file)
@@ -115,7 +115,7 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
  * \li ISC_R_SUCCESS
  */
 
-isc_result_t
+void
 isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                 isc_radix_node_t *source, isc_prefix_t *prefix);
 /*%<
@@ -127,9 +127,6 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
  * \li 'target' is not NULL and "*target" is NULL.
  * \li 'prefix' to be valid or 'source' to be non NULL and contain
  *     a valid prefix.
- *
- * Returns:
- * \li ISC_R_SUCCESS
  */
 
 void
index 1863ddc07080dd93da9599d8d857661681f7b5d6..0e1139f5375b2f95a26d6a9e8d99812e0d9a3dec 100644 (file)
  * information regarding copyright ownership.
  */
 
-/*
- * This source was adapted from MRT's RCS Ids:
- * Id: radix.c,v 1.10.2.1 1999/11/29 05:16:24 masaki Exp
- * Id: prefix.c,v 1.37.2.9 2000/03/10 02:53:19 labovit Exp
- */
-
 #include <inttypes.h>
 
 #include <isc/mem.h>
@@ -209,7 +203,7 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target,
        return ISC_R_SUCCESS;
 }
 
-isc_result_t
+void
 isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                 isc_radix_node_t *source, isc_prefix_t *prefix) {
        isc_radix_node_t *node;
@@ -254,7 +248,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                radix->head = node;
                radix->num_active_node++;
                *target = node;
-               return ISC_R_SUCCESS;
+               return;
        }
 
        u_char *addr = isc_prefix_touchar(prefix);
@@ -334,7 +328,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                                }
                        }
                        *target = node;
-                       return ISC_R_SUCCESS;
+                       return;
                } else {
                        node->prefix = *prefix;
                }
@@ -357,7 +351,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                        node->node_num[ISC_RADIX_FAMILY(prefix)] = next;
                }
                *target = node;
-               return ISC_R_SUCCESS;
+               return;
        }
 
        isc_radix_node_t *new_node = radix_node_create(radix->mctx, prefix,
@@ -396,7 +390,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
                        node->left = new_node;
                }
                *target = new_node;
-               return ISC_R_SUCCESS;
+               return;
        }
 
        if (bitlen == differ_bit) {
@@ -446,7 +440,7 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target,
        }
 
        *target = new_node;
-       return ISC_R_SUCCESS;
+       return;
 }
 
 void
index 9d31fdf07d472ca4c99a4c89329859bbb6be8885..af98ebbca69e07d116fbc531a0184c9359cd1213 100644 (file)
@@ -744,8 +744,7 @@ cfg_acl_fromconfig(const cfg_obj_t *acl_data, const cfg_obj_t *cctx,
                         * the nestedacl element, not the iptable entry.
                         */
                        setpos = (nest_level != 0 || !neg);
-                       CHECK(dns_iptable_addprefix(iptab, &addr, bitlen,
-                                                   setpos));
+                       dns_iptable_addprefix(iptab, &addr, bitlen, setpos);
 
                        if (nest_level > 0) {
                                INSIST(dacl->length < dacl->alloc);
@@ -814,8 +813,7 @@ cfg_acl_fromconfig(const cfg_obj_t *acl_data, const cfg_obj_t *cctx,
                        if (strcasecmp(name, "any") == 0) {
                                /* Iptable entry with zero bit length. */
                                setpos = (nest_level != 0 || !neg);
-                               CHECK(dns_iptable_addprefix(iptab, NULL, 0,
-                                                           setpos));
+                               dns_iptable_addprefix(iptab, NULL, 0, setpos);
 
                                if (nest_level != 0) {
                                        INSIST(dacl->length < dacl->alloc);
@@ -833,8 +831,7 @@ cfg_acl_fromconfig(const cfg_obj_t *acl_data, const cfg_obj_t *cctx,
                                 * "!none;".
                                 */
                                setpos = (nest_level != 0 || neg);
-                               CHECK(dns_iptable_addprefix(iptab, NULL, 0,
-                                                           setpos));
+                               dns_iptable_addprefix(iptab, NULL, 0, setpos);
 
                                if (!neg) {
                                        dacl->has_negatives = !neg;
index 71ffda00460abcff5ce0d52f1aa5a10954390c42..da05573cefc366348b5e87652970b1eac3673c76 100644 (file)
@@ -840,8 +840,7 @@ setup_locals(isc_interface_t *interface, dns_acl_t *localhost,
 
        /* First add localhost address */
        prefixlen = (netaddr->family == AF_INET) ? 32 : 128;
-       RETERR(dns_iptable_addprefix(localhost->iptable, netaddr, prefixlen,
-                                    true));
+       dns_iptable_addprefix(localhost->iptable, netaddr, prefixlen, true);
 
        /* Then add localnets prefix */
        result = isc_netaddr_masktoprefixlen(&interface->netmask, &prefixlen);
@@ -870,8 +869,7 @@ setup_locals(isc_interface_t *interface, dns_acl_t *localhost,
                return ISC_R_SUCCESS;
        }
 
-       RETERR(dns_iptable_addprefix(localnets->iptable, netaddr, prefixlen,
-                                    true));
+       dns_iptable_addprefix(localnets->iptable, netaddr, prefixlen, true);
 
        return ISC_R_SUCCESS;
 }
index 5861a15e8f41b2469f28673527b0fe7d8078ae37..a910b3d3442c149323f04624f591b6209be98f73 100644 (file)
@@ -52,11 +52,9 @@ ISC_RUN_TEST_IMPL(dns_acl_isinsecure) {
 
        UNUSED(state);
 
-       result = dns_acl_any(isc_g_mctx, &any);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       dns_acl_any(isc_g_mctx, &any);
 
-       result = dns_acl_none(isc_g_mctx, &none);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       dns_acl_none(isc_g_mctx, &none);
 
        dns_acl_create(isc_g_mctx, 1, &notnone);
 
index 7b916aa54548fe8906f144a718da279e0cceccc9..8a4599f64ba89f201ced85771d5dce5f3a565728 100644 (file)
@@ -49,8 +49,7 @@ insert_prefix(isc_radix_tree_t *radix, const char *str, uint16_t bitlen,
 
        prefix_from_str(str, bitlen, &pfx);
 
-       isc_result_t result = isc_radix_insert(radix, &node, NULL, &pfx);
-       assert_int_equal(result, ISC_R_SUCCESS);
+       isc_radix_insert(radix, &node, NULL, &pfx);
        node->data[RADIX_V4] = data;
 
        return node;