]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
RPZ canonical warning displays zone entry incorrectly
authorMark Andrews <marka@isc.org>
Mon, 25 Aug 2025 00:32:36 +0000 (10:32 +1000)
committerMark Andrews <marka@isc.org>
Tue, 2 Sep 2025 23:43:45 +0000 (23:43 +0000)
Do not insert a NUL into ip_str too early as the full value
is needed later.  Only insert the NUL immediately before
displaying just the prefix string.

(cherry picked from commit 283da99f02d8b58c56efee988f39db3dc18426f1)

lib/dns/rpz.c

index be2285763b455fb399e8a058560e8c3a2127cd71..596482bf482b39ef2306ea50a90b2e804e1e4f37 100644 (file)
@@ -802,7 +802,7 @@ name2ipkey(int log_level, dns_rpz_zone_t *rpz, dns_rpz_type_t rpz_type,
        dns_fixedname_t ip_name2f;
        dns_name_t ip_name;
        const char *prefix_str = NULL, *cp = NULL, *end = NULL;
-       char *cp2;
+       char *prefix_end, *cp2;
        int ip_labels;
        dns_rpz_prefix_t prefix;
        unsigned long prefix_num, l;
@@ -840,12 +840,9 @@ name2ipkey(int log_level, dns_rpz_zone_t *rpz, dns_rpz_type_t rpz_type,
                        "");
                return ISC_R_FAILURE;
        }
-       /*
-        * Patch in trailing nul character to print just the length
-        * label (for various cases below).
-        */
-       *cp2 = '\0';
+       prefix_end = cp2;
        if (prefix_num < 1U || prefix_num > 128U) {
+               *prefix_end = '\0';
                badname(log_level, src_name, "; invalid prefix length of ",
                        prefix_str);
                return ISC_R_FAILURE;
@@ -858,6 +855,7 @@ name2ipkey(int log_level, dns_rpz_zone_t *rpz, dns_rpz_type_t rpz_type,
                 * from the form "prefix.z.y.x.w"
                 */
                if (prefix_num > 32U) {
+                       *prefix_end = '\0';
                        badname(log_level, src_name,
                                "; invalid IPv4 prefix length of ", prefix_str);
                        return ISC_R_FAILURE;
@@ -936,6 +934,7 @@ name2ipkey(int log_level, dns_rpz_zone_t *rpz, dns_rpz_type_t rpz_type,
                i = prefix % DNS_RPZ_CIDR_WORD_BITS;
                aword = tgt_ip->w[prefix / DNS_RPZ_CIDR_WORD_BITS];
                if ((aword & ~DNS_RPZ_WORD_MASK(i)) != 0) {
+                       *prefix_end = '\0';
                        badname(log_level, src_name,
                                "; too small prefix length of ", prefix_str);
                        return ISC_R_FAILURE;